💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add indexids only search, closes #691
davidmezzetti634dcfc0759a
diff --git a/src/python/txtai/embeddings/base.py b/src/python/txtai/embeddings/base.pyindex 6bf5e5b9..d8a3087d 100644--- a/src/python/txtai/embeddings/base.py+++ b/src/python/txtai/embeddings/base.py@@ -87,6 +87,13 @@ class Embeddings:# Set initial configurationself.configure(config)+ def __del__(self):+ """+ Clean resources when embeddings is deleted.+ """++ self.close()+def score(self, documents):"""Builds a term weighting scoring index. Only used by word vectors models.@@ -148,7 +155,7 @@ class Embeddings:# Index graph, if necessaryif self.graph:- self.graph.index(Search(self, True), Ids(self), self.batchsimilarity)+ self.graph.index(Search(self, indexonly=True), Ids(self), self.batchsimilarity)def upsert(self, documents):"""@@ -195,7 +202,7 @@ class Embeddings:# Graph upsert, if necessaryif self.graph:- self.graph.upsert(Search(self, True), Ids(self), self.batchsimilarity)+ self.graph.upsert(Search(self, indexonly=True), Ids(self), self.batchsimilarity)def delete(self, ids):"""@@ -392,7 +399,7 @@ class Embeddings:graph = graph if self.graph else False# Execute search- results = Search(self, graph)(queries, limit, weights, index, parameters)+ results = Search(self, indexids=graph)(queries, limit, weights, index, parameters)# Create subgraphs using results, if necessaryreturn [self.graph.filter(x) for x in results] if graph else resultsdiff --git a/src/python/txtai/embeddings/search/base.py b/src/python/txtai/embeddings/search/base.pyindex 3b686d22..a2c86dfb 100644--- a/src/python/txtai/embeddings/search/base.py+++ b/src/python/txtai/embeddings/search/base.py@@ -16,17 +16,19 @@ class Search:Executes a batch search action. A search can be both index and/or database driven."""- def __init__(self, embeddings, indexids=False):+ def __init__(self, embeddings, indexids=False, indexonly=False):"""Creates a new search action.Args:embeddings: embeddings instanceindexids: searches return indexids when True, otherwise run standard search+ indexonly: always runs an index search even when a database is available"""self.embeddings = embeddings- self.indexids = indexids+ self.indexids = indexids or indexonly+ self.indexonly = indexonly# Alias embeddings attributesself.ann = embeddings.ann@@ -66,7 +68,7 @@ class Search:index = self.indexes.default()# Database search- if self.database:+ if not self.indexonly and self.database:return self.dbsearch(queries, limit, weights, index, parameters)# Default vector index query (sparse, dense or hybrid)