Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Rewrite reindex SQL function, closes #190

davidmezzetti4efe59e3081a
diff --git a/src/python/txtai/database/sqlite.py b/src/python/txtai/database/sqlite.py
index dda50b92..86aafddf 100644
--- a/src/python/txtai/database/sqlite.py
+++ b/src/python/txtai/database/sqlite.py
@@ -79,8 +79,8 @@ class SQLite(Database):
INSERT_SECTION = "INSERT INTO sections VALUES (?, ?, ?, ?, ?)"
DELETE_SECTIONS = "DELETE FROM sections WHERE id IN (SELECT id FROM batch)"
COPY_SECTIONS = (
- "INSERT INTO %s SELECT indexid-1, id, text, tags, entry FROM (SELECT row_number() OVER (ORDER BY indexid) AS indexid, "
- + "s.id, %s AS text, s.tags, s.entry FROM sections s LEFT JOIN documents d ON s.id = d.id)"
+ "INSERT INTO %s SELECT (select count(*) - 1 from sections s1 where s.indexid >= s1.indexid) indexid, "
+ + "s.id, %s AS text, s.tags, s.entry FROM sections s LEFT JOIN documents d ON s.id = d.id ORDER BY indexid"
)
STREAM_SECTIONS = "SELECT s.id, s.text, object, s.tags FROM %s s LEFT JOIN objects o ON s.id = o.id ORDER BY indexid"
DROP_SECTIONS = "DROP TABLE sections"