💡 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
Code cleanup
davidmezzetti1d084941f430
diff --git a/src/python/txtai/embeddings/base.py b/src/python/txtai/embeddings/base.pyindex fe7634de..817c0723 100644--- a/src/python/txtai/embeddings/base.py+++ b/src/python/txtai/embeddings/base.py@@ -488,7 +488,8 @@ class Embeddings:query reduced down to keyword terms"""- return self.batchterms([query])[0]+ results = self.batchterms([query])+ return results[0] if results else Nonedef batchterms(self, queries):"""diff --git a/src/python/txtai/embeddings/search/terms.py b/src/python/txtai/embeddings/search/terms.pyindex 8546de0e..f9a76d20 100644--- a/src/python/txtai/embeddings/search/terms.py+++ b/src/python/txtai/embeddings/search/terms.py@@ -38,7 +38,8 @@ class Terms:parse = self.database.parse(query)# Join terms from similar clauses (absent when the query has no similar() clause)- terms.append(" ".join(" ".join(s) for s in parse.get("similar", [])))+ if "similar" in parse:+ terms.append(" ".join(" ".join(s) for s in parse["similar"]))return termsdiff --git a/test/python/testapi/testencoding.py b/test/python/testapi/testencoding.pyindex 1133f6f2..1b7cfe99 100644--- a/test/python/testapi/testencoding.py+++ b/test/python/testapi/testencoding.py@@ -121,34 +121,6 @@ class TestEncoding(unittest.TestCase):# Test reading imageself.assertIsInstance(PIL.Image.open(BytesIO(results[0]["object"])), PIL.Image.Image)- def testMessagePackStreaming(self):- """- Test a streaming response is passed through unchanged when msgpack is requested- """-- from fastapi import FastAPI- from fastapi.responses import StreamingResponse-- from txtai.api.route import EncodingAPIRoute-- app = FastAPI()- app.router.route_class = EncodingAPIRoute-- @app.get("/stream")- def stream():- def generate():- yield b"hello"- yield b"world"-- return StreamingResponse(generate())-- client = TestClient(app)-- # A msgpack Accept header on a streaming endpoint must not try to re-wrap it (no .body)- response = client.get("stream", headers={"Accept": "application/msgpack"})- self.assertEqual(response.status_code, 200)- self.assertEqual(response.content, b"helloworld")-def testObjects(self):"""Test object encodingdiff --git a/test/python/testembeddings.py b/test/python/testembeddings.pyindex 2c7c7291..e0935665 100644--- a/test/python/testembeddings.py+++ b/test/python/testembeddings.py@@ -363,9 +363,6 @@ class TestEmbeddings(unittest.TestCase):uid = embeddings.search("feel good story", 1)[0][0]self.assertEqual(uid, 0)- def testTerms(self):- """- Test extracting keyword terms from queriesdef testLimitBindParameter(self):"""Test a LIMIT bind parameter in a content SQL query@@ -374,14 +371,6 @@ class TestEmbeddings(unittest.TestCase):embeddings = Embeddings({"keyword": True, "content": True})embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])- # Plain keyword query is returned unchanged- self.assertEqual(embeddings.terms("feel good story"), "feel good story")-- # SQL query with a similar() clause extracts its terms- self.assertEqual(embeddings.terms("select id, text from txtai where similar('feel good story')"), "feel good story")-- # SQL query without a similar() clause has no keyword terms (previously raised KeyError)- self.assertEqual(embeddings.terms("select id, text from txtai where id = 1"), "")# A ":n" LIMIT bind parameter must not crash on the candidate-count parse (str vs int)results = embeddings.search("select id from txtai order by id limit :n", parameters={"n": 2})self.assertEqual(len(results), 2)@@ -605,6 +594,23 @@ class TestEmbeddings(unittest.TestCase):# Close embeddingsembeddings.close()+ def testTerms(self):+ """+ Test extracting keyword terms from queries+ """++ embeddings = Embeddings({"keyword": True, "content": True})+ embeddings.index([(uid, text, None) for uid, text in enumerate(self.data)])++ # Plain keyword query is returned unchanged+ self.assertEqual(embeddings.terms("feel good story"), "feel good story")++ # SQL query with a similar() clause extracts its terms+ self.assertEqual(embeddings.terms("select id, text from txtai where similar('feel good story')"), "feel good story")++ # SQL query without a similar() clause has no keyword terms (previously raised KeyError)+ self.assertEqual(embeddings.terms("select id, text from txtai where id = 1"), None)+def testTruncate(self):"""Test dimensionality truncation