Implement the ChunkVector Pydantic model in storage/vector_store.py using LanceDB's LanceModel integration, establishing the vector table schema as a data contract.
Requirements
- Replace the placeholder docstring in
src/context_library/storage/vector_store.py with working code
- Define module-level constants
VECTOR_DIR and EMBEDDING_DIM
- Define a
ChunkVector class subclassing LanceModel with all fields from the persistence design
- Required fields:
chunk_hash (str), content (str), vector (Vector), domain (str), source_id (str), source_version (int), created_at (str)
VECTOR_DIR must resolve to ~/.context-library/vectors
Design Guidance
- Full implementation for
storage/vector_store.py:
"""LanceDB-backed vector index; derived and fully rebuildable from the document store."""
from lancedb.pydantic import LanceModel, Vector
VECTOR_DIR = "~/.context-library/vectors"
EMBEDDING_DIM = 384 # all-MiniLM-L6-v2; change here when swapping embedding model
class ChunkVector(LanceModel):
"""Schema for the LanceDB chunk_vectors table.
chunk_hash is the join key to the SQLite chunks table.
LanceDB is derived and disposable; it can be fully rebuilt from SQLite.
"""
chunk_hash: str # join key to SQLite chunks table
content: str # denormalized for reranker access without SQLite lookup
vector: Vector(EMBEDDING_DIM)
domain: str # supports filtered vector search by domain
source_id: str # supports filtered vector search by source
source_version: int # supports filtered vector search by version
created_at: str # ISO 8601 timestamp
Vector(EMBEDDING_DIM) is the callable from lancedb.pydantic that defines the vector column with a fixed dimensionality at the schema level. It is not the same as a Python type annotation — it must be called with the integer dimension.
EMBEDDING_DIM = 384 corresponds to all-MiniLM-L6-v2, the default embedding model provided by sentence-transformers. If the embedding model is changed later, only this constant needs updating.
content is denormalized here (duplicated from SQLite) to allow the reranker to score results without a second database round-trip.
created_at uses ISO 8601 string format (e.g., "2024-01-15T10:30:00Z") for compatibility with LanceDB's string-based filtering.
- This is the only placeholder module that contains actual executable code in the scaffold; all other placeholder modules remain docstring-only.
Acceptance Criteria
Dependencies
Phase 2, Phase 3
Parent Issue
Part of #1
Discussion
This work is detailed in discussion 2
Implement the
ChunkVectorPydantic model instorage/vector_store.pyusing LanceDB'sLanceModelintegration, establishing the vector table schema as a data contract.Requirements
src/context_library/storage/vector_store.pywith working codeVECTOR_DIRandEMBEDDING_DIMChunkVectorclass subclassingLanceModelwith all fields from the persistence designchunk_hash(str),content(str),vector(Vector),domain(str),source_id(str),source_version(int),created_at(str)VECTOR_DIRmust resolve to~/.context-library/vectorsDesign Guidance
storage/vector_store.py:Vector(EMBEDDING_DIM)is the callable fromlancedb.pydanticthat defines the vector column with a fixed dimensionality at the schema level. It is not the same as a Python type annotation — it must be called with the integer dimension.EMBEDDING_DIM = 384corresponds toall-MiniLM-L6-v2, the default embedding model provided bysentence-transformers. If the embedding model is changed later, only this constant needs updating.contentis denormalized here (duplicated from SQLite) to allow the reranker to score results without a second database round-trip.created_atuses ISO 8601 string format (e.g.,"2024-01-15T10:30:00Z") for compatibility with LanceDB's string-based filtering.Acceptance Criteria
src/context_library/storage/vector_store.pydefinesVECTOR_DIR = "~/.context-library/vectors"EMBEDDING_DIM = 384is defined as a module-level constantChunkVectoris importable:from context_library.storage.vector_store import ChunkVectorissubclass(ChunkVector, LanceModel)isTrueChunkVectormodel fields are:chunk_hash(str),content(str),vector(Vector(384)),domain(str),source_id(str),source_version(int),created_at(str)src/context_library/contains executable code beyond this file's contentsDependencies
Phase 2, Phase 3
Parent Issue
Part of #1
Discussion
This work is detailed in discussion 2