Skip to content

bm25: intern Doc.terms to cut per-document string duplication in memory and bm25.json #96

Description

@amondnet

Context

Follow-up from #84 / #91. The incremental Bm25Index keeps a Doc { terms: Vec<(String, u32)>, length } per chunk so remove_document can subtract postings. Every term string is owned per document, so a corpus with N chunks × T terms allocates N×T Strings in memory and duplicates them in bm25.json v2 (documents: {id → {term → tf}}).

Proposal

  • Intern terms: terms: Vec<(TermId, u32)> with a shared Vec<String> / HashMap<String, TermId> table on the index.
  • Persist the table once in bm25.json (schema bump to v3 with a v2 loader kept for one release).

Acceptance

  • Memory and bm25.json size measured on a mid-size repo before/after (CodSpeed benchmark added for Bm25Index::load).
  • Scores are bit-identical to v2 (existing sparse/tests.rs pass unchanged).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:proposalProposal for discussiontype:refactorCode refactoring without behavior change

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions