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 DuckDB bind parameters followed by a non-word character not being converted (#1325)

Grapette.Lff5aec468a81
diff --git a/src/python/txtai/database/duckdb.py b/src/python/txtai/database/duckdb.py
index f29088af..4c77028e 100644
--- a/src/python/txtai/database/duckdb.py
+++ b/src/python/txtai/database/duckdb.py
@@ -144,7 +144,8 @@ class DuckDB(Embedded):
# - Build list of value with position indexes
params = []
for key, value in parameters.items():
- pattern = rf"\:{key}(?=\s|$)"
+ # Match on a word boundary, bind parameters can be followed by any non-word character, i.e. `in (:x)`
+ pattern = rf"\:{key}\b"
for match in re.finditer(pattern, query):
params.append((match.start(), value))
diff --git a/test/python/testdatabase/testrdbms.py b/test/python/testdatabase/testrdbms.py
index 568949b5..5a27a8a8 100644
--- a/test/python/testdatabase/testrdbms.py
+++ b/test/python/testdatabase/testrdbms.py
@@ -737,6 +737,14 @@ class Common:
result = self.embeddings.search("select * from txtai where text like :x or text like :x", parameters={"x": "%iceberg%"})[0]
self.assertEqual(result["text"], self.data[1])
+ # Test a bind parameter followed by a non-word character
+ result = self.embeddings.search("select * from txtai where text in (:x)", parameters={"x": self.data[1]})[0]
+ self.assertEqual(result["text"], self.data[1])
+
+ # Test multiple bind parameters in the same clause
+ result = self.embeddings.search("select * from txtai where text in (:x, :y)", parameters={"x": self.data[1], "y": self.data[4]})
+ self.assertEqual({row["text"] for row in result}, {self.data[1], self.data[4]})
+
def testSparse(self):
"""
Test sparse vector search