Skip to content

Commit babb5d4

Browse files
committed
Add vector types INT8 and UINT8 test
1 parent 486b6c2 commit babb5d4

File tree

2 files changed

+56
-59
lines changed

2 files changed

+56
-59
lines changed

search_commands.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,6 @@ func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, with
15921592
if !ok {
15931593
return FTSearchResult{}, fmt.Errorf("invalid total results format")
15941594
}
1595-
15961595
var results []Document
15971596
for i := 1; i < len(data); {
15981597
docID, ok := data[i].(string)

search_test.go

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,62 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
15771577
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
15781578
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:2"))
15791579
})
1580+
1581+
It("should FTCreate VECTOR with int8 and uint8 types", Label("search", "ftcreate"), func() {
1582+
// Define INT8 vector field
1583+
hnswOptionsInt8 := &redis.FTHNSWOptions{
1584+
Type: "INT8",
1585+
Dim: 2,
1586+
DistanceMetric: "L2",
1587+
}
1588+
1589+
// Define UINT8 vector field
1590+
hnswOptionsUint8 := &redis.FTHNSWOptions{
1591+
Type: "UINT8",
1592+
Dim: 2,
1593+
DistanceMetric: "L2",
1594+
}
1595+
1596+
// Create index with INT8 and UINT8 vector fields
1597+
val, err := client.FTCreate(ctx, "idx1",
1598+
&redis.FTCreateOptions{},
1599+
&redis.FieldSchema{FieldName: "int8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsInt8}},
1600+
&redis.FieldSchema{FieldName: "uint8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsUint8}},
1601+
).Result()
1602+
1603+
Expect(err).NotTo(HaveOccurred())
1604+
Expect(val).To(BeEquivalentTo("OK"))
1605+
WaitForIndexing(client, "idx1")
1606+
1607+
// Insert vectors in int8 and uint8 format
1608+
client.HSet(ctx, "doc1", "int8_vector", "\x01\x02", "uint8_vector", "\x01\x02")
1609+
client.HSet(ctx, "doc2", "int8_vector", "\x03\x04", "uint8_vector", "\x03\x04")
1610+
1611+
// Perform KNN search on INT8 vector
1612+
searchOptionsInt8 := &redis.FTSearchOptions{
1613+
Return: []redis.FTSearchReturn{{FieldName: "int8_vector"}},
1614+
SortBy: []redis.FTSearchSortBy{{FieldName: "int8_vector", Asc: true}},
1615+
DialectVersion: 2,
1616+
Params: map[string]interface{}{"vec": "\x01\x02"},
1617+
}
1618+
1619+
resInt8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @int8_vector $vec]", searchOptionsInt8).Result()
1620+
Expect(err).NotTo(HaveOccurred())
1621+
Expect(resInt8.Docs[0].ID).To(BeEquivalentTo("doc1"))
1622+
1623+
// Perform KNN search on UINT8 vector
1624+
searchOptionsUint8 := &redis.FTSearchOptions{
1625+
Return: []redis.FTSearchReturn{{FieldName: "uint8_vector"}},
1626+
SortBy: []redis.FTSearchSortBy{{FieldName: "uint8_vector", Asc: true}},
1627+
DialectVersion: 2,
1628+
Params: map[string]interface{}{"vec": "\x01\x02"},
1629+
}
1630+
1631+
resUint8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @uint8_vector $vec]", searchOptionsUint8).Result()
1632+
Expect(err).NotTo(HaveOccurred())
1633+
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
1634+
})
1635+
15801636
})
15811637

15821638
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {
@@ -1902,62 +1958,4 @@ var _ = Describe("RediSearch commands Resp 3", Label("search"), func() {
19021958
Expect(res2).ToNot(BeEmpty())
19031959
}).ShouldNot(Panic())
19041960
})
1905-
1906-
It("should FTCreate VECTOR with int8 and uint8 types", Label("search", "ftcreate"), func() {
1907-
ctx := context.TODO()
1908-
1909-
// Define INT8 vector field
1910-
hnswOptionsInt8 := &redis.FTHNSWOptions{
1911-
Type: "INT8",
1912-
Dim: 2,
1913-
DistanceMetric: "L2",
1914-
}
1915-
1916-
// Define UINT8 vector field
1917-
hnswOptionsUint8 := &redis.FTHNSWOptions{
1918-
Type: "UINT8",
1919-
Dim: 2,
1920-
DistanceMetric: "L2",
1921-
}
1922-
1923-
// Create index with INT8 and UINT8 vector fields
1924-
val, err := client.FTCreate(ctx, "idx1",
1925-
&redis.FTCreateOptions{},
1926-
&redis.FieldSchema{FieldName: "int8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsInt8}},
1927-
&redis.FieldSchema{FieldName: "uint8_vector", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptionsUint8}},
1928-
).Result()
1929-
1930-
Expect(err).NotTo(HaveOccurred())
1931-
Expect(val).To(BeEquivalentTo("OK"))
1932-
WaitForIndexing(client, "idx1")
1933-
1934-
// Insert vectors in int8 and uint8 format
1935-
client.HSet(ctx, "doc1", "int8_vector", "\x01\x02", "uint8_vector", "\x01\x02")
1936-
client.HSet(ctx, "doc2", "int8_vector", "\x03\x04", "uint8_vector", "\x03\x04")
1937-
1938-
// Perform KNN search on INT8 vector
1939-
searchOptionsInt8 := &redis.FTSearchOptions{
1940-
Return: []redis.FTSearchReturn{{FieldName: "int8_vector"}},
1941-
SortBy: []redis.FTSearchSortBy{{FieldName: "int8_vector", Asc: true}},
1942-
DialectVersion: 2,
1943-
Params: map[string]interface{}{"vec": "\x01\x02"},
1944-
}
1945-
1946-
resInt8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @int8_vector $vec]", searchOptionsInt8).Result()
1947-
Expect(err).NotTo(HaveOccurred())
1948-
Expect(resInt8).To(BeEquivalentTo("doc1"))
1949-
1950-
// Perform KNN search on UINT8 vector
1951-
searchOptionsUint8 := &redis.FTSearchOptions{
1952-
Return: []redis.FTSearchReturn{{FieldName: "uint8_vector"}},
1953-
SortBy: []redis.FTSearchSortBy{{FieldName: "uint8_vector", Asc: true}},
1954-
DialectVersion: 2,
1955-
Params: map[string]interface{}{"vec": "\x01\x02"},
1956-
}
1957-
1958-
resUint8, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 1 @uint8_vector $vec]", searchOptionsUint8).Result()
1959-
Expect(err).NotTo(HaveOccurred())
1960-
Expect(resUint8).To(BeEquivalentTo("doc1"))
1961-
})
1962-
19631961
})

0 commit comments

Comments
 (0)