Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Delete existing file when creating new SQLite db

davidmezzetti787de6a648b1
diff --git a/src/python/txtai/database/sqlite.py b/src/python/txtai/database/sqlite.py
index a3d3afbb..7d77b366 100644
--- a/src/python/txtai/database/sqlite.py
+++ b/src/python/txtai/database/sqlite.py
@@ -4,6 +4,7 @@ SQLite module
import datetime
import json
+import os
import sqlite3
from .base import Database
@@ -133,6 +134,10 @@ class SQLite(Database):
# If this is a temporary database, copy over to database at path
if not self.path:
+ # Delete existing file, if necessary
+ if os.path.exists(path):
+ os.remove(path)
+
# Create database
connection = sqlite3.connect(path)
diff --git a/test/python/testdatabase/testembeddings.py b/test/python/testdatabase/testembeddings.py
index ea37b2c2..7c7d6700 100644
--- a/test/python/testdatabase/testembeddings.py
+++ b/test/python/testdatabase/testembeddings.py
@@ -127,10 +127,14 @@ class TestEmbeddings(unittest.TestCase):
# Test similar
result = self.embeddings.search(
- "select * from txtai where similar('feel good story') group by text having count(*) > 0 order by score desc", 5
+ "select * from txtai where similar('feel good story') group by text having count(*) > 0 order by score desc", 1
)[0]
self.assertEqual(result["text"], self.data[4])
+ # Test similar with limits
+ result = self.embeddings.search("select * from txtai where similar('feel good story', 1) limit 1")[0]
+ self.assertEqual(result["text"], self.data[4])
+
# Test where
result = self.embeddings.search("select * from txtai where text like '%iceberg%'", 1)[0]
self.assertEqual(result["text"], self.data[1])
@@ -192,7 +196,7 @@ class TestEmbeddings(unittest.TestCase):
WordVectors.build(tokens, 10, 1, vectors)
# Create dataset
- data = [(x, row, None) for x, row in enumerate(self.data)]
+ data = [(x, row.split(), None) for x, row in enumerate(self.data)]
# Create embeddings model, backed by word vectors
embeddings = Embeddings(