mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 04:32:38 +08:00
Added support to add text embedding fields with schema update
This commit is contained in:
parent
38eab6251b
commit
dede71bad9
@ -4131,7 +4131,7 @@ Option<bool> Collection::validate_alter_payload(nlohmann::json& schema_changes,
|
||||
}
|
||||
|
||||
if(!f.embed_from.empty()) {
|
||||
return Option<bool>(400, "Embedding fields can only be added at the time of collection creation.");
|
||||
embedding_fields.emplace(f.name, f);
|
||||
}
|
||||
|
||||
if(f.nested && enable_nested_fields) {
|
||||
@ -4146,7 +4146,7 @@ Option<bool> Collection::validate_alter_payload(nlohmann::json& schema_changes,
|
||||
updated_nested_fields.emplace(prefix_kv.key(), prefix_kv.value());
|
||||
|
||||
if(!prefix_kv.value().embed_from.empty()) {
|
||||
return Option<bool>(400, "Embedding fields can only be added at the time of collection creation.");
|
||||
embedding_fields.emplace(prefix_kv.key(), prefix_kv.value());
|
||||
}
|
||||
|
||||
if(is_reindex) {
|
||||
|
@ -1455,10 +1455,13 @@ TEST_F(CollectionSchemaChangeTest, UpdateSchemaWithNewEmbeddingField) {
|
||||
]
|
||||
})"_json;
|
||||
|
||||
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
|
||||
TextEmbedderManager::download_default_model();
|
||||
|
||||
auto op = collectionManager.create_collection(schema);
|
||||
ASSERT_TRUE(op.ok());
|
||||
Collection* coll = op.get();
|
||||
|
||||
|
||||
nlohmann::json update_schema = R"({
|
||||
"fields": [
|
||||
@ -1468,8 +1471,17 @@ TEST_F(CollectionSchemaChangeTest, UpdateSchemaWithNewEmbeddingField) {
|
||||
|
||||
auto res = coll->alter(update_schema);
|
||||
|
||||
ASSERT_FALSE(res.ok());
|
||||
ASSERT_EQ("Embedding fields can only be added at the time of collection creation.", res.error());
|
||||
ASSERT_TRUE(res.ok());
|
||||
ASSERT_EQ(1, coll->get_embedding_fields().size());
|
||||
|
||||
nlohmann::json doc;
|
||||
doc["names"] = {"hello", "world"};
|
||||
auto add_op = coll->add(doc.dump());
|
||||
|
||||
ASSERT_TRUE(add_op.ok());
|
||||
auto added_doc = add_op.get();
|
||||
|
||||
ASSERT_EQ(384, added_doc["embedding"].get<std::vector<float>>().size());
|
||||
}
|
||||
|
||||
TEST_F(CollectionSchemaChangeTest, DropFieldUsedForEmbedding) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user