Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Only create lsa file if model exists

davidmezzetti0e14b0bedb1e
diff --git a/src/python/txtai/embeddings.py b/src/python/txtai/embeddings.py
index be93a680..e0c0ba7b 100644
--- a/src/python/txtai/embeddings.py
+++ b/src/python/txtai/embeddings.py
@@ -250,8 +250,10 @@ class Embeddings(object):
# Sentence embeddings index
self.embeddings = faiss.read_index("%s/embeddings" % path)
- with open("%s/lsa" % path, "rb") as handle:
- self.lsa = pickle.load(handle)
+ # Dimensionality reduction
+ if self.config.get("pca"):
+ with open("%s/lsa" % path, "rb") as handle:
+ self.lsa = pickle.load(handle)
# Embedding scoring
if self.config.get("scoring"):
@@ -276,8 +278,9 @@ class Embeddings(object):
# Write sentence embeddings
faiss.write_index(self.embeddings, "%s/embeddings" % path)
- with open("%s/lsa" % path, "wb") as handle:
- pickle.dump(self.lsa, handle, protocol=pickle.HIGHEST_PROTOCOL)
+ if self.lsa:
+ with open("%s/lsa" % path, "wb") as handle:
+ pickle.dump(self.lsa, handle, protocol=pickle.HIGHEST_PROTOCOL)
# Save embedding scoring
if self.scoring: