Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Refactor check for uninitialized embeddings instance #212

davidmezzettif6b5c2f0fe4e
diff --git a/src/python/txtai/embeddings/search.py b/src/python/txtai/embeddings/search.py
index 0f083b46..7be2587d 100644
--- a/src/python/txtai/embeddings/search.py
+++ b/src/python/txtai/embeddings/search.py
@@ -39,6 +39,10 @@ class Search:
list of (id, score) per query for ann search, list of dict per query for an ann+database search
"""
+ # Return empty results if ANN is not set
+ if not self.ann:
+ return []
+
if self.database:
return self.dbsearch(queries, limit)
@@ -61,7 +65,7 @@ class Search:
embeddings = np.array([self.transform((None, query, None)) for query in queries])
# Search approximate nearest neighbor index
- results = self.ann.search(embeddings, limit) if self.ann else []
+ results = self.ann.search(embeddings, limit)
# Require scores to be greater than 0
results = [[(i, score) for i, score in r if score > 0] for r in results]