Sync reads the whole exchanges table once per archived file: no index on exchanges.archive_path
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- sqlite, typescript
- Domain
- database, performance
Research direction
Read initDatabase in src/db.ts and check how it creates the existing indexes. Add the suggested index on exchanges.archive_path, then verify that both lookups described in the issue can use it and that sync completes on an existing database. The issue reports that building the index on a large database can take several minutes.
Written by the indexing model from the issue text.
Description
What happens
On a machine with a large index, sync does not finish. For each archived conversation file, sync runs SELECT COALESCE(MAX(line_end), 0) FROM exchanges WHERE archive_path = ? (the high-water mark from #152), and getFileLastIndexed in src/db.ts filters on the same column. exchanges has no index on archive_path, so SQLite reads the whole table for every file.
Measured on v1.6.0 (Ubuntu 24.04, SQLite 3.45.1)
- The database is 11.5 GB, with 317,412 rows in
exchangesand 1,396 archived files. About 1.3 GiB of memory was free for the page cache, so each full read came from disk. - Before:
EXPLAIN QUERY PLANshowedSEARCH exchangeswith no index. One lookup ran for more than 300 s without finishing. One background sync ran for 17 hours, read 1,052 GB from disk and did not finish. - After
CREATE INDEX idx_archive_path ON exchanges(archive_path), which took 16 minutes to build on this database:- the plan shows
SEARCH exchanges USING INDEX idx_archive_path (archive_path=?); - one lookup takes 0.01 s;
- a full sync finished in 749 s (39 files copied and indexed, 1,357 skipped).
- the plan shows
Suggested fix
Add the index with the others in initDatabase:
CREATE INDEX IF NOT EXISTS idx_archive_path ON exchanges(archive_path);
On an existing large database, the first start after the update spends a few minutes building it.
Related, not fixed by the index
Text search (mode text or both) matches each word with LIKE '%word%' against user_message and assistant_message, so it also reads most of the table. On this database, one default search ran for more than 7 minutes and was stopped, and one --vector search took 131 s, including loading the embedding model. An FTS5 table could serve the text side.
- Dominant language
- TypeScript
- Stars
- 511
- Forks
- 154
- Avg merge
- 14d 20h
- Merged PRs (30d)
- 6
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from obra/episodic-memory
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
obra/episodic-memory#219 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
obra/episodic-memory#218 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
obra/episodic-memory#195 ·
-
Sync reads every changed transcript whole in hasConversationContent (1.6 GB for a 507 MB file)Possibly taken @gezerui888 claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
obra/episodic-memory#194 · 2 comments ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
obra/episodic-memory#191 ·
All issues in obra/episodic-memory
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day