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 console printing a traceback for a query with no results (#1145)

Andrew Chen7435297bace8
diff --git a/src/python/txtai/console/base.py b/src/python/txtai/console/base.py
index 9d734a92..4c9138f1 100644
--- a/src/python/txtai/console/base.py
+++ b/src/python/txtai/console/base.py
@@ -154,6 +154,11 @@ class Console(Cmd):
else:
results = self.app.search(query, limit=self.vlimit)
+ # No matches, nothing to render
+ if not results:
+ self.console.print("No results")
+ return
+
columns, table = {}, Table(box=box.SQUARE, style="#03a9f4")
# Build column list
diff --git a/test/python/testconsole.py b/test/python/testconsole.py
index 0df82bb7..c2db80b4 100644
--- a/test/python/testconsole.py
+++ b/test/python/testconsole.py
@@ -78,6 +78,18 @@ class TestConsole(unittest.TestCase):
self.assertIn("tasks", self.command(".config"))
+ def testNoResults(self):
+ """
+ Test a query that matches nothing renders a message instead of a traceback
+ """
+
+ console = Console()
+ console.app = self.embeddings
+
+ output = self.command("select id, text from txtai where id = 'missing'", console)
+ self.assertNotIn("Traceback", output)
+ self.assertIn("No results", output)
+
def testEmbeddings(self):
"""
Test embeddings index