mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Fix search on non-indexed auto embedding fields
This commit is contained in:
parent
8392e85891
commit
273e67358e
@ -1308,6 +1308,11 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
|
||||
return Option<nlohmann::json>(400, error);
|
||||
}
|
||||
|
||||
if(!search_field.index) {
|
||||
std::string error = "Field `" + search_field.name + "` is marked as a non-indexed field in the schema.";
|
||||
return Option<nlohmann::json>(400, error);
|
||||
}
|
||||
|
||||
// if(TextEmbedderManager::model_dir.empty()) {
|
||||
// std::string error = "Text embedding is not enabled. Please set `model-dir` at startup.";
|
||||
// return Option<nlohmann::json>(400, error);
|
||||
|
@ -2648,4 +2648,48 @@ TEST_F(CollectionVectorTest, TestHybridSearchInvalidAlpha) {
|
||||
ASSERT_EQ("Malformed vector query string: "
|
||||
"`alpha` parameter must be a float between 0.0-1.0.", hybrid_results.error());
|
||||
|
||||
}
|
||||
|
||||
TEST_F(CollectionVectorTest, TestSearchNonIndexedEmbeddingField) {
|
||||
nlohmann::json schema = R"({
|
||||
"name": "test",
|
||||
"fields": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "embedding",
|
||||
"type": "float[]",
|
||||
"index": false,
|
||||
"optional": true,
|
||||
"embed": {
|
||||
"from": [
|
||||
"name"
|
||||
],
|
||||
"model_config": {
|
||||
"model_name": "ts/e5-small"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})"_json;
|
||||
|
||||
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
|
||||
|
||||
auto collection_create_op = collectionManager.create_collection(schema);
|
||||
ASSERT_TRUE(collection_create_op.ok());
|
||||
|
||||
auto coll = collection_create_op.get();
|
||||
|
||||
auto add_op = coll->add(R"({
|
||||
"name": "soccer"
|
||||
})"_json.dump());
|
||||
|
||||
ASSERT_TRUE(add_op.ok());
|
||||
|
||||
auto search_res = coll->search("soccer", {"name", "embedding"}, "", {}, {}, {0});
|
||||
ASSERT_FALSE(search_res.ok());
|
||||
|
||||
ASSERT_EQ("Field `embedding` is marked as a non-indexed field in the schema.", search_res.error());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user