Skip to content

DuckDBDocStore - EARS

Parent LLD: ./LLD.md

Construction and storage

  • [x] DOC-DUCK-001: The system shall construct DuckDBDocStore with a required table_name, optional storage_path defaulting to ~/.llamabot/duckdb, and optional embedding_model defaulting to minishlab/potion-base-8M.
  • [x] DOC-DUCK-002: The system shall persist the store to a single {slugified table_name}.duckdb file under storage_path.
  • [x] DOC-DUCK-003: When sentence-transformers or duckdb is missing, the system shall raise ImportError naming pip install llamabot[duckdb].

Extensions and persistence

  • [x] DOC-DUCK-010: The system shall load the DuckDB vss and fts extensions, preferring pip-installed duckdb-core-ext-vss and duckdb-core-ext-fts wheels, and falling back to INSTALL/LOAD if the wheels are absent.
  • [x] DOC-DUCK-011: The system shall set hnsw_enable_experimental_persistence = true before attaching a disk-backed database so HNSW indexes can be stored in the file.
  • [x] DOC-DUCK-012: The optional duckdb extra shall pin DuckDB 2.x and matching VSS/FTS extension wheels.
  • [x] DOC-DUCK-013: The system shall checkpoint after writes and on close(), and shall support use as a context manager, because DuckDB WAL recovery for HNSW indexes is experimental.

Document store API

  • [x] DOC-DUCK-020: The system shall implement append, extend, retrieve, and reset.
  • [x] DOC-DUCK-021: When a document is already stored, the system shall skip appending it again.
  • [x] DOC-DUCK-022: When the store is empty, retrieve shall return an empty list.
  • [x] DOC-DUCK-023: After reset, retrieve shall return no previously stored documents.
  • [x] DOC-DUCK-024: After close and reopen on the same storage_path and table_name, the system shall retrieve previously stored documents.
  • [x] DOC-DUCK-025: When the FTS index is not incremental, after close, reopen, and append of a new document, BM25 retrieve shall return that document.

Hybrid retrieval

  • [x] DOC-DUCK-030: The system shall rank documents with DuckDB FTS BM25 and vector distance, then fuse the rankings with reciprocal rank fusion.
  • [x] DOC-DUCK-031: When a query matches a rare keyword in one document and a semantic paraphrase in another, retrieve shall return both documents.
  • [x] DOC-DUCK-032: When a query contains quotes or punctuation, FTS retrieve shall still match the remaining alphanumeric tokens.