Skip to content

Commit

Permalink
chore: improve ft.create for vector search (#3178)
Browse files Browse the repository at this point in the history
metric name in vector parameters should be case insensitive

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Jun 16, 2024
1 parent 93b4193 commit 688f286
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server/search/search_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ search::SchemaField::VectorParams ParseVectorParams(CmdArgParser* parser) {
}

if (parser->Check("DISTANCE_METRIC").ExpectTail(1)) {
params.sim = parser->Switch("L2", search::VectorSimilarity::L2, "COSINE",
search::VectorSimilarity::COSINE);
params.sim = parser->ToUpper().Switch("L2", search::VectorSimilarity::L2, "COSINE",
search::VectorSimilarity::COSINE);
continue;
}

Expand Down Expand Up @@ -141,8 +141,15 @@ optional<search::Schema> ParseSchemaOrReply(DocIndex::DataType type, CmdArgParse
params = ParseTagParams(&parser);
} else if (*type == search::SchemaField::VECTOR) {
auto vector_params = ParseVectorParams(&parser);
if (!parser.HasError() && vector_params.dim == 0) {
cntx->SendError("Knn vector dimension cannot be zero");
if (parser.HasError()) {
auto err = *parser.Error();
VLOG(1) << "Could not parse vector param " << err.index;
cntx->SendError("Parse error of vector parameters", kSyntaxErrType);
return nullopt;
}

if (vector_params.dim == 0) {
cntx->SendError("Knn vector dimension cannot be zero", kSyntaxErrType);
return nullopt;
}
params = vector_params;
Expand Down
6 changes: 6 additions & 0 deletions src/server/search/search_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -679,4 +679,10 @@ TEST_F(SearchFamilyTest, AggregateLoadGroupBy) {
IsUnordArray(IsArray("even", "true"))));
}

TEST_F(SearchFamilyTest, Vector) {
auto resp = Run({"ft.create", "ann", "ON", "HASH", "SCHEMA", "vector", "VECTOR", "HNSW", "8",
"TYPE", "FLOAT32", "DIM", "100", "distance_metric", "cosine", "M", "64"});
EXPECT_EQ(resp, "OK");
}

} // namespace dfly

0 comments on commit 688f286

Please sign in to comment.