Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Add default configuration for Embeddings, closes #393

davidmezzetti3707daaa95b8
diff --git a/src/python/txtai/embeddings/base.py b/src/python/txtai/embeddings/base.py
index 59466cbb..08a6f457 100644
--- a/src/python/txtai/embeddings/base.py
+++ b/src/python/txtai/embeddings/base.py
@@ -93,6 +93,10 @@ class Embeddings:
reindex: if this is a reindex operation in which case database creation is skipped, defaults to False
"""
+ # Set configuration to default configuration, if empty
+ if not self.config:
+ self.configure(self.defaults())
+
# Create document database, if necessary
if not reindex:
self.database = self.createdatabase()
@@ -571,6 +575,16 @@ class Embeddings:
# Query model
self.query = self.loadquery() if self.config else None
+ def defaults(self):
+ """
+ Builds a default configuration.
+
+ Returns:
+ default configuration
+ """
+
+ return {"path": "sentence-transformers/all-MiniLM-L6-v2"}
+
def loadvectors(self):
"""
Loads a vector model set in config.
diff --git a/test/python/testembeddings.py b/test/python/testembeddings.py
index db3f9902..6d7b4bab 100644
--- a/test/python/testembeddings.py
+++ b/test/python/testembeddings.py
@@ -46,6 +46,17 @@ class TestEmbeddings(unittest.TestCase):
if cls.embeddings:
cls.embeddings.close()
+ def testDefaults(self):
+ """
+ Test default configuration
+ """
+
+ # Run index with no config which will fall back to default configuration
+ embeddings = Embeddings()
+ embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])
+
+ self.assertEqual(embeddings.count(), 6)
+
def testDelete(self):
"""
Test delete