Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Set default columns when no select clause provided. Improve column selection process.

davidmezzetti0ea87a849a26
diff --git a/src/python/txtai/database/sqlite.py b/src/python/txtai/database/sqlite.py
index 0e665602..e721208c 100644
--- a/src/python/txtai/database/sqlite.py
+++ b/src/python/txtai/database/sqlite.py
@@ -160,7 +160,7 @@ class SQLite(Database):
def query(self, query, limit):
# Extract query components
- select = query.get("select", "*")
+ select = query.get("select", self.defaults())
where = query.get("where")
groupby, having = query.get("groupby"), query.get("having")
orderby, qlimit = query.get("orderby"), query.get("limit")
@@ -196,7 +196,17 @@ class SQLite(Database):
columns = [c[0] for c in self.cursor.description]
# Map results and return
- results = [{column: row[x] for x, column in enumerate(columns)} for row in self.cursor]
+ results = []
+ for row in self.cursor:
+ result = {}
+
+ # Copy columns to result. In cases with duplicate column names, find one with a value
+ for x, column in enumerate(columns):
+ if column not in result or result[column] is None:
+ result[column] = row[x]
+
+ results.append(result)
+
return results
def resolve(self, name, alias=False, compound=False):
@@ -235,6 +245,16 @@ class SQLite(Database):
# Return ids clause placeholder
return SQLite.IDS_CLAUSE % batch
+ def defaults(self):
+ """
+ Returns a list of default columns when there is no select clause.
+
+ Returns:
+ list of default columns
+ """
+
+ return "s.id, text, score"
+
def initialize(self):
"""
Creates connection and initial database schema if no connection exists.
diff --git a/src/python/txtai/embeddings/search.py b/src/python/txtai/embeddings/search.py
index 9df4233b..a2c614e1 100644
--- a/src/python/txtai/embeddings/search.py
+++ b/src/python/txtai/embeddings/search.py
@@ -101,7 +101,7 @@ class Search:
equeries.append((x, params[0]))
# Second argument is similarity candidate window
- if len(params) > 1 and params[1].isnumeric():
+ if len(params) > 1 and params[1].isdigit():
# Get largest window value across all queries
window = int(params[1]) if int(params[1]) > window else window
@@ -137,7 +137,7 @@ class Search:
for query in queries:
# Parse out qlimit
l = query.get("limit")
- if l and l.isnumeric():
+ if l and l.isdigit():
l = int(l)
qlimit = l if l and l > qlimit else qlimit