Skip to content

Commit 470693f

Browse files
committed
Fix: Ensure embedding indexes are created even when schemas are reused
When wikidata schemas already exist (from previous imports), they are reused and new_schema() is not called, which means post_schema_add() is never called, which means embedding indexes are never created. Add ensure_embedding_indexes() method that explicitly creates embedding indexes after schema initialization, regardless of whether schemas were newly created or reused. This ensures embedding search works correctly for all imports. The method: - Checks if embedding service is available - Creates embedding index for entity metadata description field - Handles case where index already exists gracefully This fixes the issue where 'similar' command in interactive mode fails with 'Index not found: CellDoesNotExisted' error.
1 parent 987f220 commit 470693f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/apps/wikidata/importer.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,46 @@ impl WikidataImporter {
556556
println!(" TYPE_LIST field definition: {:?}", *ID_TYPE_LIST);
557557
}
558558

559+
// Ensure embedding indexes are created for entity metadata description field
560+
// This is needed when schemas are reused from previous imports
561+
self.ensure_embedding_indexes().await?;
562+
563+
Ok(())
564+
}
565+
566+
/// Ensure embedding indexes exist for schema fields with IndexType::Embedding
567+
/// This is needed because when schemas are reused (not newly created),
568+
/// post_schema_add() is not called and indexes don't get created.
569+
async fn ensure_embedding_indexes(&self) -> Result<(), ImportError> {
570+
println!("\n🔍 Ensuring embedding indexes are created...");
571+
572+
let embedding_client = &self.server.neb_server.indexer.as_ref()
573+
.ok_or_else(|| ImportError::Schema("Indexer not available".to_string()))?
574+
.clients
575+
.embedding_client;
576+
577+
// Check if embedding service is available
578+
if !embedding_client.is_embedding_index_core_set() {
579+
println!("⚠️ Embedding service not initialized, skipping embedding index creation");
580+
return Ok(());
581+
}
582+
583+
// Create embedding index for entity metadata description field
584+
let description_field_id = bifrost_hasher::hash_str("description");
585+
let model = neb::index::embedding::EmbeddingModel::new("default");
586+
587+
println!(" Creating embedding index for entity metadata descriptions...");
588+
match embedding_client
589+
.new_index(ENTITY_METADATA_SCHEMA_ID, description_field_id, &model)
590+
.await
591+
{
592+
Ok(_) => println!(" ✓ Embedding index created successfully"),
593+
Err(e) => {
594+
// Index might already exist, which is fine
595+
println!(" ℹ️ Embedding index creation result: {:?}", e);
596+
}
597+
}
598+
559599
Ok(())
560600
}
561601

0 commit comments

Comments
 (0)