Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Fix issue with extractor query method

davidmezzettia0b488aaf1cf
diff --git a/src/python/txtai/pipeline/text/extractor.py b/src/python/txtai/pipeline/text/extractor.py
index 628c42e6..e1bb12b9 100644
--- a/src/python/txtai/pipeline/text/extractor.py
+++ b/src/python/txtai/pipeline/text/extractor.py
@@ -71,8 +71,8 @@ class Extractor(Pipeline):
list of (name, answer)
"""
- # Rank text by similarity for each query
- results = self.rank([query for _, query, _, _ in queue], texts)
+ # Rank texts by similarity for each query
+ results = self.query([query for _, query, _, _ in queue], texts)
# Build question-context pairs
names, questions, contexts, topns, snippets = [], [], [], [], []
@@ -127,9 +127,9 @@ class Extractor(Pipeline):
# Default to question-answering
return Questions(path, quantize, gpu, model)
- def rank(self, queries, texts):
+ def query(self, queries, texts):
"""
- Rank texts against queries. If texts is not provided, an embeddings search will be executed.
+ Rank texts by similarity for each query. If texts is empty, an embeddings search will be executed.
Returns results sorted by best match.
Args:
@@ -153,10 +153,9 @@ class Extractor(Pipeline):
must = [token.strip("+") for token in query.split() if token.startswith("+") and len(token) > 1]
mnot = [token.strip("-") for token in query.split() if token.startswith("-") and len(token) > 1]
- # Segment text is static when texts is passed in but different per query when an
- # embeddings search is run
- segment = segments[i] if isinstance(segments[i], list) else segments
- tokens = tokenlist[i] if isinstance(segments[i], list) else tokenlist
+ # Segment text is static when texts is passed in but different per query when an embeddings search is run
+ segment = segments if texts else segments[i]
+ tokens = tokenlist if texts else tokenlist[i]
# List of matches
matches = []
diff --git a/test/python/testpipeline/testextractor.py b/test/python/testpipeline/testextractor.py
index 1bf6aea7..b80a9039 100644
--- a/test/python/testpipeline/testextractor.py
+++ b/test/python/testpipeline/testextractor.py
@@ -74,7 +74,7 @@ class TestExtractor(unittest.TestCase):
Tests an empty extractor queries list
"""
- self.assertEqual(self.extractor.rank(None, None), [])
+ self.assertEqual(self.extractor.query(None, None), [])
def testGeneration(self):
"""