Repository navigation
feat(memory): BM25 section search, vector views and RRF - #125
Conversation
…usion SEARCH TEXT ranks the sections of each node's latest revision by BM25, or every revision with HISTORY. The index is a derivation written in the same transaction as the sections, so it matches the committed data at every generation and branch. Statistics are kept per tenant. Terms are accent-folded and lower-cased; dotted, dashed and underscored names are indexed whole and in parts so exact technical terms rank first. Vector records let one atom hold several vectors under named views and models (EMBED ... VIEW, VECTORS OF, NEAREST VECTORS TO). Each model has its own HNSW index of vector records beside the per-atom index, which keeps SIMILAR TO unchanged. REVISE ... EMBED stores a content vector for every section, and purge erases the vectors of a node, its revisions and its sections. Rrf.combine fuses ranked lists by reciprocal rank and FUSE now uses it.
- Text search without HISTORY reads a separate posting list for the sections of latest revisions, moved when a node gets a new revision, so it no longer scans every old revision. A derived revision-to- sections index makes that move possible inside the transaction. - Tokenization keeps combining marks outside Latin and Greek, and splits Chinese, Japanese, Thai, Lao, Khmer and Burmese runs into character bigrams. - The indexing cache keeps term counts per section span with byte and entry bounds, is cleared for purged and abandoned payloads, and only a purged payload reads as empty; other read errors fail the commit. - Vector records are keyed by owner, view and model, so concurrent writes of one view conflict instead of leaving two. Replacing a vector no longer erases the old bytes, which branches and history may still read; replaced and dropped vectors give their quota back. - NEAREST VECTORS skips sections of superseded revisions unless HISTORY is given, meters every vector it examines, scores each one once, and skips records whose payload cannot be read. - REVISE ... EMBED charges all section vectors in one commit. - MERGE BRANCH copies vectors of the revisions and sections it copies and drops vectors of atoms the branch deleted. PURGE erases vectors of the node's revisions and sections from the retained history too.
|
Pushed fixes from a review pass. This branch now also merges the latest #124.
Full build: engine 269, database 341, server 41. Each new test fails when its fix is reverted. The live run is green again, before and after SIGKILL. |
REBUILD TEXT INDEX, or Writer.rebuildTextIndex(), drops the BM25 postings, the statistics and the revision-to-section index of the current branch and indexes every stored section again in one transaction. It runs through Transaction.apply like the CREATE INDEX backfill, so it is replayed if the transaction is rebased, and its key changes go to the WAL like any other commit. Only an administrator of the default tenant may run it, because it rewrites every tenant's index.
A rebuild that failed part-way, for example on a payload with a bad checksum, left the emptied index in its transaction; inside BEGIN ... COMMIT the next commit published it. The rebuild now puts the old trees back before rethrowing. Erasing purged payloads after a checkpoint did not drop them from the text index's term cache, so a later rebuild on a branch could index Markdown that was already erased.
|
Added
Tests:
Removing either of the two resets that clear the postings and the statistics makes the corruption test fail. Live, two tenants: the other tenant's admin is refused. The rebuild re-indexed 287 sections, and BM25 then matched the Python reference on 8 of 8 queries in each tenant, before and after SIGKILL. The docs note the limits: it builds in memory, counts against the transaction page budget, and holds up other commits if it has to be redone at commit. |
Second part of the memory work, stacked on #124.
What it does
SEARCH TEXTranks sections by BM25. By default it searches each node's latest revision; withHISTORYit searches every revision.AT GENERATIONand on branches.Reader.retrieve,PR-123andsnake_caseare indexed whole as well as in parts, so exact technical terms rank first.EMBED … VIEW,VECTORS OF,NEAREST VECTORS TO).SIMILAR TOandEMBED … TEXTbehave as before.REVISE … EMBEDstores acontentvector for every section.DELETEdrops an atom's vectors.PURGEerases the vectors of the node, its revisions and its sections.Rrf.combinedoes reciprocal rank fusion with k = 60.FUSEnow uses the same terms.Slots 60 to 63 are new, still under storage format 10.
Syntax
Testing
TextSearchTest:VectorTest:REVISE, and purge.SecurityTest#textSearchAndVectorsStayInsideTheTenantshows that scores in one tenant don't move when another tenant writes.PermissionsTestchecks type grants on search.nearestVectors: removing it alone is still blocked by the owner-visibility check behind it.SEARCH TEXTagrees with a Python BM25 on 8 of 8 queries per tenant, before and after a purge.NEAREST VECTORSagrees with an exhaustive cosine scan on 12 of 12 queries per tenant.Merge order for the memory stack: #128 (CI fix), #124, #125, #126, #127, #129 (online text index rebuild), #130 (starter kit). Retarget each to main once the one below it merges. A private preview image built from #129 merged with #128 is at ghcr.io/metacoglabs/hstore-memory:0.2.0-dec80f2.