Principle:0xranx OpenContext Vector Storage
| Knowledge Sources | |
|---|---|
| Domains | Information_Retrieval, Database_Systems |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
A storage pattern for persisting embedding vectors and their metadata in a columnar vector database, enabling efficient approximate nearest neighbor (ANN) search for semantic retrieval.
Description
Vector storage addresses the need to persist and query large numbers of embedding vectors alongside their associated metadata (source file, heading path, chunk index, document type). Unlike traditional databases optimized for exact key lookups, vector databases are optimized for similarity search — finding the closest vectors to a query vector.
The system uses LanceDB, a columnar vector database built on the Apache Arrow format. Key design decisions:
- Schema design: The "chunks" table stores both the vector (as a fixed-size list of floats) and metadata columns (file_path, content, heading_path, chunk_index, doc_type, entry_id, idea_box).
- Upsert semantics: Chunks are identified by a composite key (file_path + chunk_index), enabling incremental updates without full rebuilds.
- Mixed document types: The table stores both regular documents and idea entries, distinguished by the doc_type column, enabling type-filtered search.
- Full-table loading: For keyword search, all chunks are loaded into memory, enabling BM25 scoring over the entire corpus.
Usage
Use this principle when building a search system that requires persistent vector storage with metadata. It is the storage layer behind both vector search (similarity queries) and keyword search (full corpus loading). The columnar format enables efficient filtering and projection during search.
Theoretical Basis
The vector store implements two fundamental operations:
Vector Search (ANN):
# Abstract algorithm (NOT real implementation)
def vector_search(query_vector, limit):
table = open_table("chunks")
results = table.search(query_vector).limit(limit).execute()
return [to_search_hit(r) for r in results]
Full Corpus Loading (for BM25):
# Abstract algorithm (NOT real implementation)
def get_all_chunks():
table = open_table("chunks")
return [to_search_hit(r) for r in table.query().execute()]
The LanceDB table schema defines columns for:
- id: Unique chunk identifier (file_path + chunk_index)
- vector: Fixed-size list of Float32 (embedding dimensions)
- content: The chunk text content
- heading_path: Heading hierarchy path string
- doc_type: "doc" or "idea"
- chunk_index: Index within the source document
Practical Guide
- Initialization: The vector store connects to a LanceDB database at a configured path and opens (or creates) the "chunks" table.
- Dimension handling: Vector dimensions must match the embedding model output; mismatched dimensions trigger re-initialization.
- Upsert pattern: When re-indexing a file, existing chunks for that file are removed before inserting new ones, ensuring stale chunks are eliminated.
- Clean operation: The clean operation drops the entire table, resetting the index completely.