Implementation:0xranx OpenContext VectorStore
| Knowledge Sources | |
|---|---|
| Domains | Database_Systems, Vector_Search |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for storing and retrieving embedding vectors in a LanceDB columnar vector database, implemented in Rust as part of the OpenContext core search pipeline.
Description
The VectorStore struct manages a LanceDB table named "chunks" that stores embedding vectors alongside metadata columns. It provides:
- initialize: Connects to the LanceDB database and opens (or prepares to create) the "chunks" table.
- exists: Checks whether the table has been created (index has been built).
- upsert: Inserts or updates chunks with their vectors and metadata.
- search: Performs vector similarity search (nearest neighbor query).
- get_all_chunks: Loads all chunks into memory (used for BM25 keyword search).
- create_schema: Defines the Arrow schema with vector + metadata columns.
The table schema includes columns for: id, file_path, content, heading_path, section_title, doc_type, entry_id, entry_date, entry_created_at, idea_box, chunk_index, and vector (FixedSizeList of Float32).
Usage
- Index build: Used by `Indexer` to store chunk embeddings during index building.
- Vector search: Used by `Searcher` for similarity queries.
- Keyword search: Used by `Searcher` to load all chunks for BM25 scoring.
- Index management: The `exists()` method is used to check if an index has been built.
Code Reference
Source Location
- Repository: OpenContext
- File: crates/opencontext-core/src/search/vector_store.rs
Signature
pub struct VectorStore {
db_path: PathBuf,
dimensions: usize,
db: Option<Connection>,
table: Option<Table>,
}
impl VectorStore {
/// Create a new vector store
pub fn new(db_path: PathBuf, dimensions: usize) -> Self;
/// Initialize the database connection
pub async fn initialize(&mut self) -> SearchResult<()>;
/// Check if index exists (table is open)
pub async fn exists(&self) -> bool;
/// Create the table schema
fn create_schema(&self) -> Arc<Schema>;
}
Import
use opencontext_core::search::vector_store::VectorStore;
I/O Contract
Inputs (new)
| Name | Type | Required | Description |
|---|---|---|---|
| db_path | PathBuf | Yes | LanceDB database path |
| dimensions | usize | Yes | Embedding vector dimensions |
Schema Columns
| Column | Type | Nullable | Description |
|---|---|---|---|
| id | Utf8 | No | Unique chunk identifier |
| file_path | Utf8 | No | Source file path |
| content | Utf8 | No | Chunk text content |
| heading_path | Utf8 | No | Heading hierarchy path |
| section_title | Utf8 | Yes | Optional section title |
| doc_type | Utf8 | Yes | "doc" or "idea" |
| entry_id | Utf8 | Yes | Idea entry ID (for ideas) |
| entry_date | Utf8 | Yes | Idea entry date |
| entry_created_at | Utf8 | Yes | Idea entry creation timestamp |
| idea_box | Utf8 | Yes | Idea box name |
| chunk_index | UInt32 | No | Index within source document |
| vector | FixedSizeList<Float32> | No | Embedding vector |
Usage Examples
Initialize and Check
use opencontext_core::search::vector_store::VectorStore;
let mut store = VectorStore::new(lancedb_path.into(), 1536);
store.initialize().await?;
if store.exists().await {
println!("Index exists");
} else {
println!("No index — need to build");
}
Used in Indexer Pipeline
// The Indexer creates and uses VectorStore internally:
// 1. Chunk documents
// 2. Generate embeddings
// 3. Upsert chunks with vectors into VectorStore
// 4. VectorStore persists to LanceDB