mirror of
https://github.com/redis/go-redis.git
synced 2025-04-16 09:23:06 +03:00
Add vector types INT8 and UINT8 test (#3299)
This commit is contained in:
parent
8269e6a22a
commit
a402c55344
@ -1626,6 +1626,63 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
|
||||
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
|
||||
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:2"))
|
||||
})
|
||||
|
||||
It("should FTCreate VECTOR with int8 and uint8 types", Label("search", "ftcreate"), func() {
|
||||
SkipBeforeRedisVersion(7.9, "doesn't work with older redis")
|
||||
// Define INT8 vector field
|
||||
hnswOptionsInt8 := &redis.FTHNSWOptions{
|
||||
Type: "INT8",
|
||||
Dim: 2,
|
||||
DistanceMetric: "L2",
|
||||
}
|
||||
|
||||
// Define UINT8 vector field
|
||||
hnswOptionsUint8 := &redis.FTHNSWOptions{
|
||||
Type: "UINT8",
|
||||
Dim: 2,
|
||||
DistanceMetric: "L2",
|
||||
}
|
||||
|
||||
// Create index with INT8 and UINT8 vector fields
|
||||
val, err := client.FTCreate(ctx, "idx1",
|
||||
&redis.FTCreateOptions{},
|
||||
&redis.FieldSchema{FieldName: "int8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsInt8}},
|
||||
&redis.FieldSchema{FieldName: "uint8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsUint8}},
|
||||
).Result()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(val).To(BeEquivalentTo("OK"))
|
||||
WaitForIndexing(client, "idx1")
|
||||
|
||||
// Insert vectors in int8 and uint8 format
|
||||
client.HSet(ctx, "doc1", "int8_vector", "\x01\x02", "uint8_vector", "\x01\x02")
|
||||
client.HSet(ctx, "doc2", "int8_vector", "\x03\x04", "uint8_vector", "\x03\x04")
|
||||
|
||||
// Perform KNN search on INT8 vector
|
||||
searchOptionsInt8 := &redis.FTSearchOptions{
|
||||
Return: []redis.FTSearchReturn{{FieldName: "int8_vector"}},
|
||||
SortBy: []redis.FTSearchSortBy{{FieldName: "int8_vector", Asc: true}},
|
||||
DialectVersion: 2,
|
||||
Params: map[string]interface{}{"vec": "\x01\x02"},
|
||||
}
|
||||
|
||||
resInt8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @int8_vector $vec]", searchOptionsInt8).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(resInt8.Docs[0].ID).To(BeEquivalentTo("doc1"))
|
||||
|
||||
// Perform KNN search on UINT8 vector
|
||||
searchOptionsUint8 := &redis.FTSearchOptions{
|
||||
Return: []redis.FTSearchReturn{{FieldName: "uint8_vector"}},
|
||||
SortBy: []redis.FTSearchSortBy{{FieldName: "uint8_vector", Asc: true}},
|
||||
DialectVersion: 2,
|
||||
Params: map[string]interface{}{"vec": "\x01\x02"},
|
||||
}
|
||||
|
||||
resUint8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @uint8_vector $vec]", searchOptionsUint8).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user