Repository navigation
fix(search): slice Postgres FTS chunk inserts into bounded batches (#2133) - #2135
zaidrain06 wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…asicmachines-co#2133) Signed-off-by: Said Yagmur <[email protected]>
70ced1d to
e04afb0
Compare
k0nnect
left a comment
There was a problem hiding this comment.
thanks for picking up #2133. fork prs don't get the full ci here, so i checked out e04afb0 and ran the checks locally (python 3.12, uv sync):
uv run ruff check .fails:src/basic_memory/repository/postgres_search_repository.py:4:8: F401 json imported but unused. the only use was thejson.dumps(chunks)this pr removes.uv run ruff format --checkwants to reformattests/repository/test_accepted_note_search_repository.py(theall_rowscomprehension and thebyte_slicedcall).pytest tests/repository/test_accepted_note_search_repository.py: 5 passed, 2 skipped, 1 failed. the failure is the newtest_postgres_replace_fts_chunks_slices_by_rows_and_byte_cap:TypeError: SearchIndexRow.__init__() missing 2 required positional arguments: 'created_at' and 'updated_at'. it fails while building the row, so_replace_fts_chunksand the row/byte slicing asserts never run.
one gap against the issue: #2133 asks that searching text near the end of a multi-mb note returns the note. both new tests use the recording session and never reach postgres. test_postgres_refresh_entity_chunks_large_script_content in the same file looks like a good model for a postgres-backed one.
the slicing helper itself reads right to me: a single batch serializes the same as the old json.dumps(chunks), and an oversized chunk gets its own batch.
|
Thanks for checking this locally, @k0nnect! Pushed
Both |
…FTS test Signed-off-by: Said Yagmur <[email protected]>
a0d065a to
aa5701b
Compare
k0nnect
left a comment
There was a problem hiding this comment.
re-ran on aa5701b:
uv run ruff check .anduv run ruff format --check .are both clean.- sqlite: 6 passed, 3 skipped.
- postgres (
pgvector/pgvector:pg16): 9 passed, including the new multi-mb tail-search test.
all four points are covered. looks good from my side.
Summary
Fixes #2133
Slices PostgreSQL full-text search chunk writes (
INSERT INTO search_index_fts_chunks ... FROM jsonb_to_recordset(CAST(:chunks AS JSONB))) into bounded JSONB batches (POSTGRES_FTS_CHUNK_INSERT_MAX_ROWS = 200orPOSTGRES_FTS_CHUNK_INSERT_MAX_BYTES = 2_000_000, whichever comes first) inside the caller's existing session and transaction.Changes
src/basic_memory/repository/postgres_fts_chunks.py: AddedPOSTGRES_FTS_CHUNK_INSERT_MAX_ROWS = 200,POSTGRES_FTS_CHUNK_INSERT_MAX_BYTES = 2_000_000, andslice_postgres_fts_chunk_json_batches()to partition serialized chunk payloads by row count and UTF-8 byte size.src/basic_memory/repository/postgres_search_repository.py: Updated_replace_fts_chunksto execute oneINSERT ... FROM jsonb_to_recordsetper bounded slice inside the same session/transaction.src/basic_memory/repository/accepted_note_search_repository.py: UpdatedAcceptedNoteSearchRepository.refresh_entityto use the same bounded slicing forINSERT_ACCEPTED_NOTE_FTS_CHUNKS_SQL.tests/repository/test_accepted_note_search_repository.py: Added tests verifying multi-statement slicing on >200-chunk notes, tail token preservation, and byte-cap splitting.Verification
INSERTstatement with identical row payloads.statement_timeoutwhile preserving fix(core): replace an entity's search rows in one transaction #1623 transaction atomicity.