Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Added batch indexing for transformer based indices (#23)

davidmezzetti3f5c6997a87e
diff --git a/src/python/txtai/embeddings.py b/src/python/txtai/embeddings.py
index 90cbff20..38ffb16d 100644
--- a/src/python/txtai/embeddings.py
+++ b/src/python/txtai/embeddings.py
@@ -4,6 +4,7 @@ Embeddings module
import pickle
import os
+import shutil
import numpy as np
@@ -249,6 +250,10 @@ class Embeddings(object):
with open("%s/config" % path, "rb") as handle:
self.config = pickle.load(handle)
+ # Build full path to embedded vectors file
+ if self.config.get("storevectors"):
+ self.config["path"] = os.path.join(path, self.config["path"])
+
# Sentence embeddings index
self.embeddings = ANN.create(self.config)
self.embeddings.load("%s/embeddings" % path)
@@ -278,6 +283,12 @@ class Embeddings(object):
# Create output directory, if necessary
os.makedirs(path, exist_ok=True)
+ # Copy vectors file
+ if self.config.get("storevectors"):
+ shutil.copyfile(self.config["path"], os.path.join(path, os.path.basename(self.config["path"])))
+
+ self.config["path"] = os.path.basename(self.config["path"])
+
# Write index configuration
with open("%s/config" % path, "wb") as handle:
pickle.dump(self.config, handle, protocol=pickle.HIGHEST_PROTOCOL)