localvectordb package
Everything below is re-exported at the top level: import it as
from localvectordb import LocalVectorDB, not from the submodule it happens
to be defined in.
This page renders the whole public surface for browsing, but it deliberately
does not own the cross-reference targets – each symbol is documented
canonically once, on the page for the module that defines it (linked under
Submodules below). Documenting it in both places is what produced Sphinx’s
“more than one target found” warnings, since autodoc emits unqualified
references from type annotations and cannot choose between two equal targets.
Hence :no-index:; removing it re-introduces ~75 warnings.
LocalVectorDB - Document-First Vector Database with SQLite + FAISS
A Python library providing a document-focused vector database built on SQLite, FAISS, and pluggable embedding providers. Offers both local and remote (client-server) usage with a unified API.
Copyright (c) 2025-2026 Tom Villani Licensed under the MIT License.
- class localvectordb.LocalVectorDB(*args: Any, **kwargs: Any)
Bases:
LocalTuningMixin,PipelineMixin,SearchMixin,MetadataMixin,CrudMixin,ComparisonMixin,RepairMixin,LocalVectorDBCoreDocument-first vector database with SQLite + FAISS + embeddings
This is the main interface for LocalVectorDB v1.0, designed around documents rather than chunks. All chunking is handled internally.
- Parameters:
name (str) – Database name (used for file naming)
base_path (str, optional) – Directory to store database files, by default “.lvdb”
metadata_schema (str | Dict[str, MetadataField], optional) – Schema definition for metadata fields
doc_id_pattern (str, optional) – Pattern for auto-generating document IDs, by default “doc_{idx}”
embedding_provider (str, optional) – Embedding provider name, by default “ollama”
embedding_model (str, optional) – Embedding model name, by default “nomic-embed-text”
embedding_config (Dict[str, Any], optional) – Configuration for embedding provider
chunking_method (str, optional) – Chunking method, by default “sentences”
chunk_size (int, optional) – Maximum tokens per chunk, by default 500
chunk_overlap (int, optional) – Overlap between consecutive chunks, by default 1. Measured in the unit of
chunking_method(sentences for “sentences”, tokens for “tokens”, words for “words”, lines for “lines”/”code-blocks”, characters for “characters”, paragraphs for “paragraphs”), NOT tokens — only “tokens” shares its unit withchunk_size. Keep it small (e.g. 1-3); a value larger than the number of units a chunk holds produces highly redundant chunks.enable_gpu (bool, optional) – Whether to use GPU for FAISS, by default False
enable_fts (bool, optional) – Whether to enable full-text search, by default True
create_if_not_exists (bool, default = True) – If False, raises DatabaseNotFoundError if the database doesn’t exist.
- class localvectordb.ChunkerFactory
Bases:
objectFactory for creating chunkers
- CHUNKERS: dict[str, Type[PositionTrackingChunker]] = {'characters': <class 'localvectordb.chunking.CharChunker'>, 'code-blocks': <class 'localvectordb.chunking.CodeBlockChunker'>, 'lines': <class 'localvectordb.chunking.LineChunker'>, 'paragraphs': <class 'localvectordb.chunking.ParagraphChunker'>, 'sections': <class 'localvectordb.chunking.SectionChunker'>, 'sentences': <class 'localvectordb.chunking.SentenceChunker'>, 'tokens': <class 'localvectordb.chunking.TokenChunker'>, 'words': <class 'localvectordb.chunking.WordChunker'>}
- classmethod create_chunker(method: str | Type[PositionTrackingChunker], max_tokens: int = 500, overlap: int = 0, **kwargs) PositionTrackingChunker
Create a chunker instance
- class localvectordb.EmbeddingRegistry
Bases:
objectRegistry for embedding providers with plugin discovery
- classmethod register(name: str, provider_class: Type[EmbeddingProvider]) None
Register a new embedding provider
- classmethod get(name: str) Type[EmbeddingProvider]
Get an embedding provider by name
- classmethod create_provider(provider_name: str, model: str, **kwargs: Any) EmbeddingProvider
Create an embedding provider instance
- classmethod refresh_plugins() None
Force re-discovery of plugins (useful for testing)
- class localvectordb.RerankerRegistry
Bases:
objectRegistry for reranker providers with plugin discovery.
- classmethod register(name: str, provider_class: Type[Reranker]) None
Register a new reranker provider.
- classmethod create_reranker(provider_name: str, model: str | None = None, **kwargs: Any) Reranker
Create a reranker instance.
- classmethod refresh_plugins() None
Force re-discovery of plugins (useful for testing).
- class localvectordb.RemoteVectorDB(name: str, base_url: str = 'http://127.0.0.1:5000', api_key: str | None = None, *, create_if_not_exists: bool = True, metadata_schema: Dict[str, MetadataField] | None = None, embedding_provider: str = 'ollama', embedding_model: str = 'nomic-embed-text', embedding_config: Dict[str, Any] | None = None, chunking_method: str = 'sentences', chunk_size: int = 500, chunk_overlap: int = 1, enable_gpu: bool = False, enable_fts: bool = True, sqlite_profile: Literal['balanced', 'fast_ingest', 'read_optimized', 'durable', 'memory_saver'] = 'balanced', sqlite_pragma_overrides: Dict[str, Any] | None = None, request_timeout: int | None = None, authorization_header: str = 'Authorization', max_retries: int = 3, retry_delay: float = 1.0, max_concurrent_requests: int = 5, connection_pool_limits: Limits | None = None)
Bases:
TuningMixin,BaseVectorDBClient for interacting with a LocalVectorDB server.
This client provides the same interface as LocalVectorDB but connects to a remote server via HTTP.
- Parameters:
name (str) – Name of the database
base_url (str) – URL of the LocalVectorDB server (e.g., “http://localhost:5000”)
api_key (str, optional) – API key for authentication. If not provided, checks LVDB_API_KEY environment variable. Specify a custom environment variable by passing “$CUSTOM_ENV_VARIABLE” for this parameter.
create_if_not_exists (bool, default=True) – Whether to create the database if it doesn’t exist
metadata_schema (Dict[str, MetadataField], optional) – Schema definition for metadata fields
embedding_provider (str, optional) – Provider for embeddings, by default “ollama”
embedding_model (str, optional) – Model to use for embeddings, by default “nomic-embed-text”
embedding_config (Dict[str, Any], optional) – Configuration for embedding provider
chunking_method (str, optional) – Method for chunking documents, by default “sentences”
chunk_size (int, optional) – Maximum tokens per chunk, by default 500
chunk_overlap (int, optional) – Overlap between consecutive chunks, by default 1. Measured in the unit of
chunking_method(sentences, words, lines, characters, paragraphs), NOT tokens — onlychunking_method="tokens"shares its unit withchunk_size. Keep it small (e.g. 1-3).enable_gpu (bool, optional) – Whether to use GPU for FAISS, by default False
enable_fts (bool, optional) – Whether to enable full-text search, by default True
request_timeout (int, optional) – Timeout for HTTP requests
authorization_header (str, default = "Authorization") – The server can be configured to accept alternate headers, and the client can too.
max_retries (int) – Max number of retries for a request
retry_delay (int) – The delay after a failed request before trying again
max_concurrent_requests (int) – How many maximum requests for embeddings
connection_pool_limits (httpx.Limits) – Parameters for the httpx client connection pool
- __init__(name: str, base_url: str = 'http://127.0.0.1:5000', api_key: str | None = None, *, create_if_not_exists: bool = True, metadata_schema: Dict[str, MetadataField] | None = None, embedding_provider: str = 'ollama', embedding_model: str = 'nomic-embed-text', embedding_config: Dict[str, Any] | None = None, chunking_method: str = 'sentences', chunk_size: int = 500, chunk_overlap: int = 1, enable_gpu: bool = False, enable_fts: bool = True, sqlite_profile: Literal['balanced', 'fast_ingest', 'read_optimized', 'durable', 'memory_saver'] = 'balanced', sqlite_pragma_overrides: Dict[str, Any] | None = None, request_timeout: int | None = None, authorization_header: str = 'Authorization', max_retries: int = 3, retry_delay: float = 1.0, max_concurrent_requests: int = 5, connection_pool_limits: Limits | None = None)
- property embedding_provider: EmbeddingProvider
Return the remote embedding provider instance.
This provider proxies embedding requests to the server, providing API parity with LocalVectorDB while keeping operations server-side.
- property metadata_schema: Dict[str, MetadataField]
Return the metadata schema.
- property embedding_model: str
Return the embedding model name
- property embedding_dimension: int
Return the dimension of the embeddings
- property chunk_size: int
Return the maximum tokens per chunk
- property chunk_overlap: int
Return the chunk overlap, in the unit of
chunking_method(not tokens unless the method is"tokens").
- property chunking_method: str
Return the chunking method
- property fts_enabled: bool
Return whether full-text search is enabled
- upsert(documents: str | List[str], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None) List[str]
Insert or update documents in the database
- Parameters:
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Only fields declared in the database’s metadata schema are stored; other fields are dropped (the server logs a warning).
ids (Optional[Union[str, List[str]]]) – Document IDs (auto-generated if not provided)
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (float, optional) – Skip adding any chunks that are more similar than this value. Good for “pre-deduplication”
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- insert(documents: str | List[str], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise') List[str]
Insert new documents into the database
- Parameters:
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Only fields declared in the database’s metadata schema are stored; other fields are dropped (the server logs a warning).
ids (Optional[Union[str, List[str]]]) – Document IDs (auto-generated if not provided)
batch_size (int) – Batch size for processing, by default 100
errors (Literal["ignore", "raise"]) – How to handle document ID conflicts, by default “raise”
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- upsert_from_file(file_paths: str | Path | List[str | Path], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, extractor_kwargs: Dict[str, Any] | None = None) List[str]
Insert or update documents from files using file extraction.
- Parameters:
file_paths (Union[str, Path, List[Union[str, Path]]]) – Path(s) to files to extract and upsert
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Will be merged with extracted metadata.
ids (Optional[Union[str, List[str]]]) – Document IDs. If not provided, will use filename without extension.
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
extractor_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the extractor
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- Raises:
FileNotFoundError – If any of the specified files don’t exist
ValueError – If extraction fails for any file
- insert_from_file(file_paths: str | Path | List[str | Path], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise', extractor_kwargs: Dict[str, Any] | None = None) List[str]
Insert new documents from files using file extraction.
- Parameters:
file_paths (Union[str, Path, List[Union[str, Path]]]) – Path(s) to files to extract and insert
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Will be merged with extracted metadata.
ids (Optional[Union[str, List[str]]]) – Document IDs. If not provided, will use filename without extension.
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
errors (Literal["ignore", "raise"]) – How to handle document ID conflicts, by default “raise”
extractor_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the extractor
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- Raises:
FileNotFoundError – If any of the specified files don’t exist
ValueError – If extraction fails for any file
DuplicateDocumentIDError – If errors=”raise” and document ID conflicts occur
- upsert_from_chunks(chunks_by_document: Dict[str, List[Chunk] | List[str]], metadata: Dict[str, Dict[str, Any]] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None) List[str]
Upsert documents from pre-chunked data.
- Parameters:
chunks_by_document (Dict[str, Union[List[Chunk], List[str]]]) – Dictionary mapping document IDs to their chunks. Chunks can be either: - List[Chunk]: Full Chunk objects with position information - List[str]: Simple strings that will be converted to Chunk objects
metadata (Optional[Dict[str, Dict[str, Any]]], default=None) – Dictionary mapping document IDs to their metadata
batch_size (int, default=100) – Number of embeddings to generate at once
similarity_threshold (Optional[float], default=None) – If provided, filters out chunks that are too similar to existing chunks
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- insert_from_chunks(chunks_by_document: Dict[str, List[Chunk] | List[str]], metadata: Dict[str, Dict[str, Any]] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise') List[str]
Insert documents from pre-chunked data with conflict handling.
- Parameters:
chunks_by_document (Dict[str, Union[List[Chunk], List[str]]]) – Dictionary mapping document IDs to their chunks
metadata (Optional[Dict[str, Dict[str, Any]]], default=None) – Dictionary mapping document IDs to their metadata
batch_size (int, default=100) – Number of embeddings to generate at once
similarity_threshold (Optional[float], default=None) – If provided, filters out chunks that are too similar to existing chunks
errors (Literal["ignore", "raise"], default="raise") – How to handle document ID conflicts
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- Raises:
DuplicateDocumentIDError – If a document ID already exists and errors=”raise”
- get(ids: str | List[str]) Document | List[Document]
Retrieve documents by ID
- Parameters:
- Returns:
Retrieved document(s)
- Return type:
- Raises:
DocumentNotFoundError – If any requested documents are not found
- get_chunk_embeddings(chunk_ids: str | List[str]) ndarray
Get embeddings for existing chunks in the database
- update(doc_id: str, content: str | None = None, metadata: Dict[str, Any] | None = None) bool
Update a document’s content and/or metadata
- Parameters:
- Returns:
True if document was updated, False if no updates needed (content and metadata already match the database)
- Return type:
- Raises:
DocumentNotFoundError – Raised if doc_id does not exist.
- patch(doc_id: str, ops: List[Dict[str, Any]], *, expect_hash: str | None = None, metadata: Dict[str, Any] | None = None) PatchResult
Patch a document’s content with find/replace or span-splice ops.
See
localvectordb.LocalVectorDB.patchfor the contract and op shapes. Raises DocumentNotFoundError (missing), PatchConflictError (staleexpect_hash), or PatchError (unmatched/ambiguous/overlapping op).
- query(query: str, *, search_type: Literal['vector', 'keyword', 'hybrid'] = 'hybrid', return_type: Literal['documents', 'chunks', 'sections', 'context', 'enriched'] | None = None, search_level: Literal['chunks', 'sections', 'documents', 'fused'] = 'chunks', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, section_weight: float = 0.65, context_window: int = 2, context_unit: str = 'chunks', context_truncate: bool = False, semantic_dedup_threshold: float | None = None, document_scoring_method: Literal['best', 'average', 'frequency_boost'] = 'frequency_boost', document_scoring_options: dict | None = None, reranker: Any | None = None, reranker_config: Dict[str, Any] | None = None, rerank_k: int | None = None) List[QueryResult]
Unified query interface for all search types
- Parameters:
query (str) – Query text
search_type (Literal['vector', 'keyword', 'hybrid']) – Type of search to perform
return_type (Literal['documents', 'chunks', 'context', 'enriched']) – Whether to return full documents, individual chunks, or chunks with context
k (int) – Maximum number of results to return
score_threshold (float) – Minimum score threshold (0-1, higher=better)
filters (Optional[Dict[str, Any]]) – Metadata filters. Filter fields must be declared in the database’s metadata schema; unknown fields or unsupported operators are rejected by the server with an error.
vector_weight (float) – Weight for vector search in hybrid mode (0-1)
context_window (int) – Number of chunks before and after to include when return_type=’context’
semantic_dedup_threshold (Optional[float]) – Similarity threshold for semantic deduplication (0-1, higher=more similar)
document_scoring_method (str) – Method for aggregating chunk scores into document scores
document_scoring_options (dict, optional) – Parameters controlling the various scoring methods
- Returns:
Search results with normalized scores
- Return type:
List[QueryResult]
- query_multi_column(query: str, *, columns: List[str] | None = None, search_type: Literal['vector', 'keyword', 'hybrid'] = 'hybrid', return_type: Literal['documents', 'chunks'] = 'documents', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, document_scoring_method: Literal['best', 'average', 'frequency_boost'] = 'frequency_boost', document_scoring_options: dict | None = None) List[QueryResult]
Query across multiple columns (main content + embedding-enabled metadata fields)
- Parameters:
query (str) – Query text
columns (Optional[List[str]]) – Specific columns to search. If None, searches all embedding-enabled fields plus main content. Use ‘content’ for main document content.
search_type (Literal['vector', 'keyword', 'hybrid']) – Type of search to perform
return_type (Literal['documents', 'chunks']) – Whether to return full documents or individual chunks
k (int) – Maximum number of results to return
score_threshold (float) – Minimum score threshold (0-1, higher=better)
filters (Optional[Dict[str, Any]]) – Metadata filters to apply
vector_weight (float) – Weight for vector search in hybrid mode (0-1)
document_scoring_method (DocumentScoringMethod) – Method for aggregating chunk scores into document scores
document_scoring_options (dict, optional) – Parameters for the scoring method
- Returns:
Search results with column attribution
- Return type:
List[QueryResult]
- filter(where: Dict[str, Any] | None = None, order_by: str | None = None, limit: int | None = None, offset: int = 0) List[Document]
Filter documents using enhanced metadata filtering
This method now supports advanced MongoDB-style filtering with operators like $gt, $lt, $contains, $exists, etc. Raw SQL support has been removed for security reasons.
- Parameters:
where (Optional[Dict[str, Any]]) –
Filter conditions using either simple format or MongoDB-style operators.
Simple format:
{"author": "John Doe", "year": 2023}
Advanced format with operators:
{ "author": {"$eq": "John Doe"}, "year": {"$gte": 2020, "$lte": 2024}, "tags": {"$contains": "python"}, "rating": {"$in": [4, 5]}, "$and": [ {"category": "tech"}, {"$or": [{"lang": "en"}, {"lang": "es"}]} ] }
Supported operators:
Comparison: $eq, $ne, $gt, $lt, $gte, $lte, $in, $nin
String: $like, $ilike, $contains, $startswith, $endswith
Existence: $exists, $not_exists
Type: $type
Logical: $and, $or, $not
JSON: $contains, $not_contains (for JSON fields)
order_by (Optional[str]) – ORDER BY clause (field name with optional ASC/DESC) Examples: “created_at DESC”, “author ASC”, “rating”
limit (Optional[int]) – Maximum number of results
offset (int) – Number of results to skip
- Returns:
Filtered documents
- Return type:
List[Document]
Examples
Simple filtering:
# Simple equality docs = db.filter(where={"author": "John Doe"}) # Multiple conditions (AND) docs = db.filter(where={"author": "John Doe", "year": 2023})
Advanced filtering:
# Range queries docs = db.filter(where={ "year": {"$gte": 2020, "$lte": 2024}, "rating": {"$gt": 4.0} }) # String operations docs = db.filter(where={ "title": {"$contains": "python"}, "author": {"$startswith": "Dr."} }) # List operations docs = db.filter(where={ "category": {"$in": ["tech", "science"]}, "tags": {"$contains": "tutorial"} }) # Logical operations docs = db.filter(where={ "$and": [ {"year": {"$gte": 2020}}, {"$or": [ {"author": "John Doe"}, {"author": "Jane Smith"} ]} ] }) # Existence checks docs = db.filter(where={ "optional_field": {"$exists": False}, "required_field": {"$exists": True} })
Ordering and pagination:
# Order by field docs = db.filter( where={"category": "tech"}, order_by="created_at DESC", limit=10, offset=20 )
Notes
All queries are converted to safe parameterized SQL on the server
Field names are validated against the metadata schema
Raw SQL is no longer supported to prevent injection attacks
JSON fields support special operations like $contains
- query_builder() QueryBuilderInterface
Create a new RemoteQueryBuilder for this database.
The RemoteQueryBuilder provides a fluent API for building complex queries that are executed server-side, including semantic filters. It is typed as the shared
QueryBuilderInterface, so the same fluent chain is portable to aLocalVectorDB.- Returns:
A new query builder instance (a
RemoteQueryBuilder)- Return type:
QueryBuilderInterface
Examples
Basic query with semantic filter:
results = (db.query_builder() .search("machine learning") .filter("year", gte_=2020) .semantic_filter("methodology", "neural networks", threshold=0.8) .limit(10) .execute())
Complex multi-criteria query:
results = (db.query_builder() .search("quantum computing", search_type="hybrid") .filter("publication_type", "paper") .filter("citations", gte_=50) .semantic_filter("approach", "quantum machine learning", threshold=0.75) .order_by("publication_date", "desc") .limit(25) .execute())
- save() None
Save the database (no-op for remote client)
- update_metadata_schema(new_schema: str | Dict[str, Any], drop_columns: bool = False, column_mapping: dict | None = None) Dict[str, Any]
Update the metadata schema for the remote database
This method allows you to add new metadata fields, modify existing ones, or remove fields from the schema. Existing document data is preserved.
- Parameters:
new_schema (Union[str, Dict[str, Any]]) – The new metadata schema to apply. Can be: - str: Schema name from common schemas (e.g., ‘research_papers’) - Dict[str, MetadataField]: Complete field definitions - Dict[str, str]: Simple type-only definitions (e.g., {‘field’: ‘text’}) - Dict[str, tuple]: Tuple definitions (type, indexed) or (type, indexed, required) - Dict[str, dict]: Full field configuration objects
drop_columns (bool, default=False) – Whether to actually drop columns that are no longer in the schema. If False, columns are kept but removed from schema for safety.
column_mapping (dict, optional) – Optionally provide a mapping dict with old-column (key) -> new-column (value)
- Returns:
Summary of changes made including: - added_fields: List of newly added field names - removed_fields: List of removed field names - modified_fields: List of modified fields with change details - populated_defaults: List of fields where default values were populated - dropped_columns: List of actually dropped columns (if drop_columns=True) - warnings: List of warnings about potential issues - errors: List of any errors encountered
- Return type:
Dict[str, Any]
Examples
Add new metadata fields:
new_schema = { 'category': {'type': 'text', 'indexed': True, 'required': True, 'default_value': 'general'}, 'rating': {'type': 'real', 'default_value': 0.0}, 'tags': {'type': 'json', 'default_value': []} } changes = db.update_metadata_schema(new_schema) print(f"Added fields: {changes['added_fields']}") print(f"Populated defaults: {changes['populated_defaults']}")
Use shorthand syntax:
new_schema = { 'category': 'text', # Simple type 'priority': ('integer', False, True), # (type, indexed, required) 'rating': ('real', True) # (type, indexed) } changes = db.update_metadata_schema(new_schema)
Apply a common schema:
changes = db.update_metadata_schema('research_papers')
Notes
Field names cannot conflict with reserved columns: id, content, content_hash, created_at, updated_at
Removed fields are removed from the schema but columns are kept for data safety
Type changes are recorded but don’t modify existing data (SQLite limitation)
Index changes are applied immediately
Changes are applied in a transaction and rolled back on error
- get_metadata_schema_info() Dict[str, Any]
Get detailed information about the current metadata schema
- Returns:
Dictionary containing: - fields: Dict of field definitions - field_count: Number of fields - indexed_fields: List of indexed field names - required_fields: List of required field names - field_types: Summary of field types used
- Return type:
Dict[str, Any]
Examples
Get schema information:
schema_info = db.get_metadata_schema_info() print(f"Total fields: {schema_info['field_count']}") print(f"Indexed fields: {schema_info['indexed_fields']}") print(f"Required fields: {schema_info['required_fields']}") print(f"Field types: {schema_info['field_types']}") # Detailed field information for field_name, field_info in schema_info['fields'].items(): print(f"{field_name}: {field_info['type']} " f"(indexed={field_info['indexed']}, required={field_info['required']})")
- property healthy: bool
Check if the remote database server is healthy and accessible.
This property performs a lightweight ping to the server to verify connectivity and server responsiveness. Results are cached for 60 seconds to avoid excessive network requests.
- Returns:
True if server is healthy and accessible, False otherwise
- Return type:
- property closed: bool
Check if the connection to the remote database is closed.
Note: This is a legacy property name. For checking server health, use the ‘healthy’ property instead.
- Returns:
False (remote connections don’t have a traditional “closed” state)
- Return type:
- close() None
Close the database connection and HTTP clients
- classmethod database_exists(db_name: str, base_url: str = 'http://127.0.0.1:5000', api_key: str | None = None, authorization_header: str = 'Authorization') bool
Check if a database exists on the server
- async upsert_async(documents: str | List[str], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, **kwargs) List[str]
Insert or update documents in the database
- Parameters:
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Only fields declared in the database’s metadata schema are stored; other fields are dropped (the server logs a warning).
ids (Optional[Union[str, List[str]]]) – Document IDs (auto-generated if not provided)
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (float, optional) – If provided, skip chunks which have semantic similarity greater than this value (pre-deduplication)
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- async insert_async(documents: str | List[str], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise', **kwargs) List[str]
Insert new documents into the database
- Parameters:
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Only fields declared in the database’s metadata schema are stored; other fields are dropped (the server logs a warning).
ids (Optional[Union[str, List[str]]]) – Document IDs (auto-generated if not provided)
batch_size (int) – Batch size for processing, by default 100
errors (Literal["ignore", "raise"]) – How to handle document ID conflicts, by default “raise”
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- async upsert_from_file_async(file_paths: str | Path | List[str | Path], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, max_concurrent_chunks: int = 3, max_concurrent_embeddings: int = 2, extractor_kwargs: Dict[str, Any] | None = None) List[str]
Insert or update documents from files using file extraction (async).
- Parameters:
file_paths (Union[str, Path, List[Union[str, Path]]]) – Path(s) to files to extract and upsert
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Will be merged with extracted metadata.
ids (Optional[Union[str, List[str]]]) – Document IDs. If not provided, will use filename without extension.
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
extractor_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the extractor
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- Raises:
FileNotFoundError – If any of the specified files don’t exist
ValueError – If extraction fails for any file
- async insert_from_file_async(file_paths: str | Path | List[str | Path], metadata: Dict[str, Any] | List[Dict[str, Any]] | None = None, ids: str | List[str] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise', max_concurrent_chunks: int = 3, max_concurrent_embeddings: int = 2, extractor_kwargs: Dict[str, Any] | None = None) List[str]
Insert new documents from files using file extraction (async).
- Parameters:
file_paths (Union[str, Path, List[Union[str, Path]]]) – Path(s) to files to extract and insert
metadata (Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]) – Metadata for documents. Will be merged with extracted metadata.
ids (Optional[Union[str, List[str]]]) – Document IDs. If not provided, will use filename without extension.
batch_size (int) – Batch size for processing, by default 100
similarity_threshold (Optional[float]) – Skip chunks that are too similar to existing chunks
errors (Literal["ignore", "raise"]) – How to handle document ID conflicts, by default “raise”
max_concurrent_chunks (int) – Maximum concurrent chunk processing (unused for remote)
max_concurrent_embeddings (int) – Maximum concurrent embedding requests (unused for remote)
extractor_kwargs (Optional[Dict[str, Any]]) – Additional keyword arguments passed to the extractor
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- Raises:
FileNotFoundError – If any of the specified files don’t exist
ValueError – If extraction fails for any file
DuplicateDocumentIDError – If errors=”raise” and document ID conflicts occur
- async upsert_from_chunks_async(chunks_by_document: Dict[str, List[Chunk] | List[str]], metadata: Dict[str, Dict[str, Any]] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, max_concurrent_chunks: int = 3, max_concurrent_embeddings: int = 2) List[str]
Upsert documents from pre-chunked data (async).
- Parameters:
chunks_by_document (Dict[str, Union[List[Chunk], List[str]]]) – Dictionary mapping document IDs to their chunks. Chunks can be either: - List[Chunk]: Full Chunk objects with position information - List[str]: Simple strings that will be converted to Chunk objects
metadata (Optional[Dict[str, Dict[str, Any]]], default=None) – Dictionary mapping document IDs to their metadata
batch_size (int, default=100) – Number of embeddings to generate at once
similarity_threshold (Optional[float], default=None) – If provided, filters out chunks that are too similar to existing chunks
max_concurrent_chunks (int) – Maximum concurrent chunk processing (unused for remote)
max_concurrent_embeddings (int) – Maximum concurrent embedding requests (unused for remote)
- Returns:
List of document IDs that were upserted
- Return type:
List[str]
- async insert_from_chunks_async(chunks_by_document: Dict[str, List[Chunk] | List[str]], metadata: Dict[str, Dict[str, Any]] | None = None, batch_size: int | None = None, similarity_threshold: float | None = None, errors: Literal['ignore', 'raise'] = 'raise', max_concurrent_chunks: int = 3, max_concurrent_embeddings: int = 2) List[str]
Insert documents from pre-chunked data with conflict handling (async).
- Parameters:
chunks_by_document (Dict[str, Union[List[Chunk], List[str]]]) – Dictionary mapping document IDs to their chunks
metadata (Optional[Dict[str, Dict[str, Any]]], default=None) – Dictionary mapping document IDs to their metadata
batch_size (int, default=100) – Number of embeddings to generate at once
similarity_threshold (Optional[float], default=None) – If provided, filters out chunks that are too similar to existing chunks
errors (Literal["ignore", "raise"], default="raise") – How to handle document ID conflicts
max_concurrent_chunks (int) – Maximum concurrent chunk processing (unused for remote)
max_concurrent_embeddings (int) – Maximum concurrent embedding requests (unused for remote)
- Returns:
List of document IDs that were actually inserted
- Return type:
List[str]
- Raises:
DuplicateDocumentIDError – If a document ID already exists and errors=”raise”
- async count_async(filters: Dict[str, Any] | None = None) int
Count documents matching filters asynchronously.
- async update_async(doc_id: str, content: str | None = None, metadata: Dict[str, Any] | None = None) bool
Update a document’s content and/or metadata
- Parameters:
- Returns:
True if document was updated, False if no updates needed (content and metadata already match the database)
- Return type:
- Raises:
DocumentNotFoundError – Raised if doc_id does not exist.
- async patch_async(doc_id: str, ops: List[Dict[str, Any]], *, expect_hash: str | None = None, metadata: Dict[str, Any] | None = None) PatchResult
Patch a document’s content asynchronously. Same contract as
patch().
- async query_async(query: str, *, search_type: Literal['vector', 'keyword', 'hybrid'] = 'hybrid', return_type: Literal['documents', 'chunks', 'sections', 'context', 'enriched'] | None = None, search_level: Literal['chunks', 'sections', 'documents', 'fused'] = 'chunks', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, section_weight: float = 0.65, context_window: int = 2, context_unit: str = 'chunks', context_truncate: bool = False, semantic_dedup_threshold: float | None = None, document_scoring_method: Literal['best', 'average', 'frequency_boost'] = 'frequency_boost', document_scoring_options: dict | None = None, reranker: Any | None = None, reranker_config: Dict[str, Any] | None = None, rerank_k: int | None = None) List[QueryResult]
Unified query interface for all search types
- Parameters:
query (str) – Query text
search_type (Literal['vector', 'keyword', 'hybrid']) – Type of search to perform
return_type (Literal['documents', 'chunks']) – Whether to return full documents or individual chunks
k (int) – Maximum number of results to return
score_threshold (float) – Minimum score threshold (0-1, higher=better)
filters (Optional[Dict[str, Any]]) – Metadata filters. Filter fields must be declared in the database’s metadata schema; unknown fields or unsupported operators are rejected by the server with an error.
vector_weight (float) – Weight for vector search in hybrid mode (0-1)
context_window (int) – Number of chunks before and after to include when return_type=’context’
semantic_dedup_threshold (Optional[float]) – Similarity threshold for semantic deduplication (0-1, higher=more similar)
document_scoring_method (str) – Method for aggregating chunk scores into document scores
document_scoring_options (dict) – Optional parameters specific to each scoring method
- Returns:
Search results with normalized scores
- Return type:
List[QueryResult]
- async query_multi_column_async(query: str, *, columns: List[str] | None = None, search_type: Literal['vector', 'keyword', 'hybrid'] = 'hybrid', return_type: Literal['documents', 'chunks'] = 'documents', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, document_scoring_method: Literal['best', 'average', 'frequency_boost'] = 'frequency_boost', document_scoring_options: dict | None = None) List[QueryResult]
Async query across multiple columns (main content + embedding-enabled metadata fields)
- Parameters:
query (str) – Query text
columns (Optional[List[str]]) – Specific columns to search. If None, searches all embedding-enabled fields plus main content. Use ‘content’ for main document content.
search_type (Literal['vector', 'keyword', 'hybrid']) – Type of search to perform
return_type (Literal['documents', 'chunks']) – Whether to return full documents or individual chunks
k (int) – Maximum number of results to return
score_threshold (float) – Minimum score threshold (0-1, higher=better)
filters (Optional[Dict[str, Any]]) – Metadata filters to apply
vector_weight (float) – Weight for vector search in hybrid mode (0-1)
document_scoring_method (DocumentScoringMethod) – Method for aggregating chunk scores into document scores
document_scoring_options (dict, optional) – Parameters for the scoring method
- Returns:
Search results with column attribution
- Return type:
List[QueryResult]
- async filter_async(where: Dict[str, Any] | None = None, order_by: str | None = None, limit: int | None = None, offset: int = 0) List[Document]
Filter documents using enhanced metadata filtering
- Parameters:
- Returns:
Filtered documents
- Return type:
List[Document]
- async save_async() None
No-op for remote databases
- async close_async() None
Close HTTP clients
- async update_metadata_schema_async(new_schema: str | Dict[str, Any], drop_columns: bool = False, column_mapping: dict | None = None) Dict[str, Any]
Update the metadata schema for the database asynchronously
This method allows you to add new metadata fields, modify existing ones, or remove fields from the schema. Existing document data is preserved.
- Parameters:
new_schema (Union[str, Dict[str, Any]]) – The new metadata schema to apply. Can be: - str: Schema name from common schemas (e.g., ‘research_papers’) - Dict with field definitions
drop_columns (bool, default=False) – Whether to actually drop columns that are no longer in the schema. If False, columns are kept but removed from schema for safety.
column_mapping (dict, optional) – Optionally provide a mapping dict with old-column (key) -> new-column (value)
- Returns:
Summary of changes made including: - added_fields: List of newly added field names - removed_fields: List of removed field names - modified_fields: List of modified fields with change details - populated_defaults: List of fields where default values were populated - dropped_columns: List of actually dropped columns (if drop_columns=True) - warnings: List of warnings about potential issues - errors: List of any errors encountered
- Return type:
Dict[str, Any]
Examples
Add new metadata fields:
new_schema = { 'category': { 'type': 'text', 'indexed': True }, 'priority': { 'type': 'integer', 'default_value': 0 } } changes = await db.update_metadata_schema_async(new_schema) print(f"Added fields: {changes['added_fields']}")
Apply a common schema:
changes = await db.update_metadata_schema_async('research_papers')
- async get_metadata_schema_info_async() Dict[str, Any]
Get detailed information about the current metadata schema asynchronously
- Returns:
Dictionary containing: - fields: Dict of field definitions - field_count: Number of fields - indexed_fields: List of indexed field names - required_fields: List of required field names - field_types: Summary of field types used
- Return type:
Dict[str, Any]
Examples
Get schema information:
schema_info = await db.get_metadata_schema_info_async() print(f"Total fields: {schema_info['field_count']}") print(f"Indexed fields: {schema_info['indexed_fields']}") print(f"Required fields: {schema_info['required_fields']}") print(f"Field types: {schema_info['field_types']}") # Detailed field information for field_name, field_info in schema_info['fields'].items(): print(f"{field_name}: {field_info['type']} " f"(indexed={field_info['indexed']}, required={field_info['required']})")
- set_sqlite_tuning(profile: str, overrides: Dict[str, Any] | None = None, persist: bool = True) None
Apply SQLite tuning profile via remote server.
- auto_tune(workload: Dict[str, Any] | None = None, interactive: bool = False, apply: bool = False) Dict[str, Any]
Get auto-tuning recommendations from the remote server.
The recommendation is computed on the server (from the server’s own system resources), not the client machine.
interactiveis not supported over HTTP – pass an explicitworkloaddict instead.
- sqlite_optimize() None
Run SQLite PRAGMA optimize via remote server.
- sqlite_vacuum() None
Run SQLite VACUUM via remote server.
- checkpoint_if_wal_large(wal_mb_threshold: int = 128) bool
Check if remote WAL is large and checkpoint if needed.
- query_stream(query: str, *, search_type: str = 'hybrid', return_type: str = 'documents', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, batch_size: int = 10, context_window: int = 2, context_unit: str = 'chunks', context_truncate: bool = False, document_scoring_method: str = 'frequency_boost', document_scoring_options: Dict[str, Any] | None = None)
Stream query results from the server via SSE.
Yields lists of QueryResult objects as they arrive from the server.
- Parameters:
- Yields:
List[QueryResult] – Batches of query results as they stream from the server.
- async query_stream_async(query: str, *, search_type: str = 'hybrid', return_type: str = 'documents', k: int = 10, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None, vector_weight: float = 0.5, batch_size: int = 10, context_window: int = 2, context_unit: str = 'chunks', context_truncate: bool = False, document_scoring_method: str = 'frequency_boost', document_scoring_options: Dict[str, Any] | None = None)
Async version of query_stream. Yields lists of QueryResult.
- compare_documents(doc_id_1: str, doc_id_2: str) float
Compare two documents and return their similarity score.
- async compare_documents_async(doc_id_1: str, doc_id_2: str) float
Async version of compare_documents.
- compare_documents_detailed(doc_id_1: str, doc_id_2: str, chunk_threshold: float = 0.7) DocumentComparisonResult
Compare two documents with detailed chunk-level analysis.
- Parameters:
- Returns:
Detailed comparison result with per-chunk alignments.
- Return type:
- async compare_documents_detailed_async(doc_id_1: str, doc_id_2: str, chunk_threshold: float = 0.7) DocumentComparisonResult
Async version of compare_documents_detailed.
- nearest_neighbors(doc_id: str, k: int = 5, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None) List[QueryResult]
Find nearest neighbors for a document.
- Parameters:
- Returns:
List of nearest neighbor results.
- Return type:
List[QueryResult]
- async nearest_neighbors_async(doc_id: str, k: int = 5, score_threshold: float = 0.0, filters: Dict[str, Any] | None = None) List[QueryResult]
Async version of nearest_neighbors.
- pairwise_similarity_matrix(doc_ids: List[str] | None = None) DocumentSimilarityMatrix
Compute pairwise similarity matrix for documents.
- Parameters:
doc_ids (Optional[List[str]]) – Document IDs to include. If None, uses all documents.
- Returns:
Matrix with similarity scores between all document pairs.
- Return type:
- async pairwise_similarity_matrix_async(doc_ids: List[str] | None = None) DocumentSimilarityMatrix
Async version of pairwise_similarity_matrix.
- localvectordb.VectorDB(name: str, base_path: str | Path, **kwargs) LocalVectorDB | RemoteVectorDB
Enhanced factory function that returns the appropriate VectorDB instance based on whether base_path looks like a URL or a local path, with optional async support.
This factory automatically handles the differences between local and remote implementations, and between sync and async variants, making it easy to switch between them.
- Parameters:
name (str) – Name of the database
base_path (Union[str, Path]) – Path or URL to the database. If it starts with ‘http://’ or ‘https://’, a RemoteVectorDB will be created. Otherwise, a LocalVectorDB will be created.
**kwargs (dict) –
Additional arguments to pass to the appropriate constructor.
These include: - metadata_schema: Dict[str, MetadataField] - Schema for metadata fields - embedding_provider: str - Provider for embeddings (“ollama”, “openai”) - embedding_model: str - Model name for embeddings - embedding_config: Dict[str, Any] - Config for embedding provider - chunking_method: str - Method for chunking (“sentences”, “tokens”, etc.) - chunk_size: int - Maximum tokens per chunk - chunk_overlap: int - Overlap in the method’s own unit, not tokens (except “tokens”); keep small (1-3) - enable_gpu: bool - Whether to use GPU for FAISS - enable_fts: bool - Whether to enable full-text search - create_if_not_exists: bool - Whether to create if not exists
For RemoteVectorDB, these include: - api_key: str - API key for authentication - request_timeout: int - Timeout for HTTP requests - max_retries: int - Number of retry attempts - retry_delay: float - Base delay between retries - connection_pool_limits: httpx.Limits - HTTP connection pool settings
- Returns:
An instance of the appropriate vector database class
- Return type:
Union[LocalVectorDB, RemoteVectorDB]
Examples
Sync local database:
from localvectordb import VectorDB from localvectordb.core import MetadataField, MetadataFieldType # Create a sync local database db = VectorDB( "my_docs", "./vector_storage", metadata_schema={ 'author': MetadataField(type=MetadataFieldType.TEXT, indexed=True), 'date': MetadataField(type=MetadataFieldType.DATE, indexed=True) }, embedding_model="nomic-embed-text", chunk_size=500 )
Sync remote database:
# Create a sync remote database connection db = VectorDB( "my_docs", "http://localhost:5000", api_key="your_api_key", metadata_schema={ 'author': MetadataField(type=MetadataFieldType.TEXT, indexed=True), 'date': MetadataField(type=MetadataFieldType.DATE, indexed=True) } ) # Async built in async with db as async_db: doc_ids = await async_db.upsert_async(["Document 1", "Document 2"])
Notes
The factory function automatically filters out incompatible parameters for each implementation
Local databases require appropriate dependencies (FAISS, SQLite)
Remote databases require a running LocalVectorDB server
- Raises:
ImportError – If required dependencies are not available for the chosen implementation
ValueError – If invalid parameters are provided for the chosen implementation
- class localvectordb.Document(id: str, content: str, metadata: Dict[str, ~typing.Any]=<factory>, created_at: datetime | None = None, updated_at: datetime | None = None, content_hash: str | None = None, chunks: List[Chunk] | None = None, sections: List[Section] | None = None)
Bases:
objectA document in the vector database
- id: str
- content: str
- class localvectordb.QueryResult(id: str, score: float, type: ~typing.Literal['document', 'chunk', 'section', 'context', 'enriched', 'group', 'aggregation'], content: str, metadata: ~typing.Dict[str, ~typing.Any] = <factory>, document_id: str | None = None, position: ~localvectordb.core.ChunkPosition | None = None)
Bases:
objectResult from a search query
- id: str
- score: float
- type: Literal['document', 'chunk', 'section', 'context', 'enriched', 'group', 'aggregation']
- content: str
- position: ChunkPosition | None = None
- get_context(original: str, window: int = 100) str | None
Get context around chunk (only for chunk results)
- classmethod from_dict(data: dict) QueryResult | None
Create a QueryResult from a dictionary response
- __init__(id: str, score: float, type: ~typing.Literal['document', 'chunk', 'section', 'context', 'enriched', 'group', 'aggregation'], content: str, metadata: ~typing.Dict[str, ~typing.Any] = <factory>, document_id: str | None = None, position: ~localvectordb.core.ChunkPosition | None = None) None
- class localvectordb.Chunk(content: str, position: ChunkPosition, tokens: int, index: int, faiss_id: int | None = None, content_hash: str | None = None)
Bases:
objectInternal representation of a document chunk.
Encapsulates the content, position metadata, token count, and optional FAISS index identifier for a text segment.
- Parameters:
content (str) – The text content of the chunk.
position (ChunkPosition) – The location of this chunk in the original document.
tokens (int) – Number of tokens in this chunk.
index (int) – Sequential index of the chunk within the document.
faiss_id (int, optional) – Identifier in the FAISS index, if applicable.
- content: str
- position: ChunkPosition
- tokens: int
- index: int
- calculate_content_hash() str
Calculate SHA-256 hash of chunk content
- class localvectordb.ChunkPosition(start: int, end: int, line: int, column: int, end_line: int, end_column: int)
Bases:
objectExact position tracking for a chunk in the original document.
- Parameters:
start (int) – Character start position in the original document.
end (int) – Character end position in the original document.
line (int) – Line number in the original document (1-based).
column (int) – Column number in the original document (1-based).
end_line (int) – Line number of end of chunk in original document (1-based)
end_column (int) – Column number of end of chunk in original document (1-based)
- start: int
- end: int
- line: int
- column: int
- end_line: int
- end_column: int
- to_dict() dict
Convert the ChunkPosition to a dictionary.
- Returns:
Dictionary representation with keys ‘start’, ‘end’, ‘line’, ‘column’.
- Return type:
Examples
>>> pos = ChunkPosition(start=0, end=10, line=1, column=1, end_line=1, end_column=10) >>> pos.to_dict() {'start': 0, 'end': 10, 'line': 1, 'column': 1, 'end_line': 1, 'end_column': 10}
- classmethod from_dict(data: dict) ChunkPosition
Create a ChunkPosition instance from a dictionary.
- Parameters:
data (dict) – Dictionary with keys ‘start’, ‘end’, ‘line’, ‘column’.
- Returns:
The constructed ChunkPosition object.
- Return type:
Examples
>>> data = {'start': 0, 'end': 10, 'line': 1, 'column': 1, 'end_line': 1, 'end_column': 10} >>> ChunkPosition.from_dict(data) ChunkPosition(start=0, end=10, line=1, column=1, end_line=1, end_column=10)
- class localvectordb.MetadataField(type: MetadataFieldType | str | Type, indexed: bool = False, required: bool = False, default_value: Any = None, embedding_enabled: bool = False, fts_enabled: bool = False)
Bases:
objectDefines a metadata field for documents.
- Parameters:
type (MetadataFieldType or str or Type) – The type of the metadata field.
indexed (bool, optional) – Whether the field is indexed in the database, by default False.
required (bool, optional) – Whether the field is required, by default False.
default_value (Any, optional) – Default value for the field if not provided, by default None.
embedding_enabled (bool, optional) – Whether this field should have its own embeddings for vector search. Only applicable to TEXT and JSON fields, by default False.
fts_enabled (bool, optional) – Whether this field should have full-text search enabled. Only applicable to TEXT fields, by default False.
- type: MetadataFieldType | str | Type
- indexed: bool = False
- required: bool = False
- default_value: Any = None
- embedding_enabled: bool = False
- fts_enabled: bool = False
- class localvectordb.MetadataFieldType(*values)
-
- TEXT = 'text'
- INTEGER = 'integer'
- REAL = 'real'
- BOOLEAN = 'boolean'
- DATE = 'date'
- JSON = 'json'
- class localvectordb.Section(index: int, heading: str | None, heading_level: int | None, start_pos: int, end_pos: int, start_line: int | None = None, end_line: int | None = None, content_hash: str | None = None, metadata: Dict[str, Any] | None = None, faiss_id: int | None = None, chunks: List[Chunk] | None = None)
Bases:
objectA section within a document, grouping multiple chunks.
Sections are an overlay on top of existing chunking. They provide a mid-level abstraction between documents and chunks for hierarchical retrieval.
- index: int
- start_pos: int
- end_pos: int
- classmethod from_boundary(boundary: SectionBoundary, content_hash: str, faiss_id: int | None = None, chunks: List[Chunk] | None = None) Section
Create a Section from a SectionBoundary.
- __init__(index: int, heading: str | None, heading_level: int | None, start_pos: int, end_pos: int, start_line: int | None = None, end_line: int | None = None, content_hash: str | None = None, metadata: Dict[str, Any] | None = None, faiss_id: int | None = None, chunks: List[Chunk] | None = None) None
- class localvectordb.SectionBoundary(index: int, heading: str | None, heading_level: int | None, start_pos: int, end_pos: int, start_line: int | None = None, end_line: int | None = None, metadata: Dict[str, Any] | None = None)
Bases:
objectBoundary information for a detected section in a document.
Used during ingestion to track where sections start and end in the original text.
- index: int
- start_pos: int
- end_pos: int
- class localvectordb.ChunkAlignment(chunk_index_1: int, chunk_index_2: int, similarity: float)
Bases:
objectAlignment between a chunk in one document and its best match in another.
- Parameters:
- chunk_index_1: int
- chunk_index_2: int
- similarity: float
- classmethod from_dict(data: Dict[str, Any]) ChunkAlignment
Reconstruct from a dict produced by
to_dict().
- class localvectordb.DocumentComparisonResult(doc_id_1: str, doc_id_2: str, overall_similarity: float, chunk_alignments: List[ChunkAlignment], matched_ratio_1: float, matched_ratio_2: float, unmatched_chunks_1: List[int], unmatched_chunks_2: List[int])
Bases:
objectRich comparison result between two documents.
- Parameters:
doc_id_1 (str) – ID of the first document.
doc_id_2 (str) – ID of the second document.
overall_similarity (float) – Centroid-level cosine similarity between documents.
chunk_alignments (List[ChunkAlignment]) – Best match per chunk in doc_1, sorted by similarity descending.
matched_ratio_1 (float) – Fraction of doc_1 chunks with a match >= threshold.
matched_ratio_2 (float) – Fraction of doc_2 chunks with a match >= threshold.
unmatched_chunks_1 (List[int]) – Chunk indices in doc_1 with no match >= threshold.
unmatched_chunks_2 (List[int]) – Chunk indices in doc_2 with no match >= threshold.
- doc_id_1: str
- doc_id_2: str
- overall_similarity: float
- chunk_alignments: List[ChunkAlignment]
- matched_ratio_1: float
- matched_ratio_2: float
- classmethod from_dict(data: Dict[str, Any]) DocumentComparisonResult
Reconstruct from a dict produced by
to_dict().
- class localvectordb.DocumentSimilarityMatrix(matrix: ndarray, doc_ids: List[str], embeddings: ndarray)
Bases:
objectNxN similarity matrix for a set of documents.
- Parameters:
matrix (np.ndarray) – (N, N) array of pairwise similarity scores.
doc_ids (List[str]) – Ordered document IDs matching rows/columns.
embeddings (np.ndarray) – (N, D) document embeddings used to compute the matrix.
- matrix: ndarray
- embeddings: ndarray
- classmethod from_dict(data: Dict[str, Any]) DocumentSimilarityMatrix
Reconstruct from a dict produced by
to_dict().
- exception localvectordb.BaseLocalVectorDBException
Bases:
ExceptionBase class for all LocalVectorDB exceptions.
- exception localvectordb.DatabaseError
Bases:
BaseLocalVectorDBExceptionRaised for general database operation failures.
- exception localvectordb.DatabaseNotFoundError
Bases:
DatabaseError,KeyErrorRaised if the Database cannot be found
- exception localvectordb.DocumentNotFoundError(message: str, missing_ids: str | List[str] | None = None)
Bases:
DatabaseError,KeyErrorRaised when one or more requested documents cannot be found
- exception localvectordb.DuplicateDocumentIDError
Bases:
DatabaseError,ValueErrorRaised when inserting document(s) and the id(s) already exist
- exception localvectordb.IndexIntegrityError
Bases:
DatabaseErrorRaised when the SQLite rows and the FAISS index disagree in a way that corrupts query results – notably duplicate
faiss_idvalues, which cause one vector to be attributed to two different documents.Recover with
lvdb db <name> repair.
- exception localvectordb.UnsupportedIndexOperationError
Bases:
DatabaseErrorRaised when an operation is not supported by the configured FAISS index type.
Most commonly:
IndexHNSWFlatcannot remove vectors, so documents cannot be deleted or replaced in a database backed by it.
- exception localvectordb.MetadataFilterError
Bases:
DatabaseError,ValueErrorRaised when there’s an error in metadata filter specification or processing
- exception localvectordb.PatchConflictError(message: str, expected: str | None = None, actual: str | None = None)
Bases:
DatabaseErrorRaised when a document patch’s
expect_hashprecondition does not match the storedcontent_hash– i.e. the document changed since the caller read it.This is a distinct outcome from “document not found” and “no-op”: the document exists and the ops are valid, but applying them would clobber a concurrent write. Surfaces as HTTP 409 on the server.
- exception localvectordb.PatchError
Bases:
DatabaseError,ValueErrorRaised when a document patch’s ops cannot be applied: an unmatched or ambiguous
find, an out-of-range or overlapping splice, or a malformed op.The whole patch fails atomically – no partial write. Surfaces as HTTP 422 on the server.
- exception localvectordb.EmbeddingError
Bases:
BaseLocalVectorDBException,RuntimeErrorRaised when an embedding provider fails to generate embeddings.
- exception localvectordb.OllamaNotFoundError
Bases:
EmbeddingErrorRaised when Ollama is not installed or not running.
- exception localvectordb.ConfigurationError
Bases:
BaseLocalVectorDBException,RuntimeErrorRaised when configuration is invalid or inconsistent.
- exception localvectordb.ValidationError
Bases:
BaseLocalVectorDBException,ValueErrorRaised when there’s a validation error in input data
- exception localvectordb.ConnectionPoolError
Bases:
BaseLocalVectorDBExceptionRaised when a database connection cannot be acquired from the pool.
- exception localvectordb.RerankerError
Bases:
BaseLocalVectorDBException,RuntimeErrorRaised when there’s an error in reranking operations.
- exception localvectordb.CursorError
Bases:
BaseLocalVectorDBExceptionBase class for cursor-related errors.
- exception localvectordb.CursorExpiredError
Bases:
CursorErrorRaised when a cursor has expired or been closed.
- exception localvectordb.CursorExhaustedError
Bases:
CursorErrorRaised when attempting to fetch from an exhausted cursor.
- class localvectordb.BackupManager(database_path: str | Path, faiss_index_path: str | Path | None = None, config: BackupConfig | None = None, db: Any | None = None)
Bases:
objectMain backup and restore manager for LocalVectorDB.
Provides comprehensive backup and recovery capabilities including full backups, incremental backups, and point-in-time recovery using SQLite’s backup API and FAISS index management.
- Parameters:
database_path (Union[str, Path]) – Path to the LocalVectorDB database file
faiss_index_path (Union[str, Path], optional) – Path to the FAISS index file. If None, inferred from database_path.
config (BackupConfig, optional) – Backup configuration. If None, uses default configuration.
db (LocalVectorDB, optional) –
The live database these paths belong to. Pass this to back up a database that is open and may be written to concurrently: the backup then holds the database’s write lock and flushes the FAISS index to disk for the duration of the snapshot, so the SQLite copy and the index copy are mutually consistent.
Without it (the path-only form) the two stores are copied without coordination. A backup taken while a write is in flight can capture SQLite rows whose vectors are not yet in the copied index – i.e. dangling rows. So the path-only form is safe only for a database that is closed, or that is otherwise known to be quiescent.
Examples
Create a full backup of a closed database:
manager = BackupManager("/path/to/mydb.sqlite") backup_id = manager.create_backup(BackupType.FULL) print(f"Backup created: {backup_id}")
Create a consistent backup of a live, open database:
manager = BackupManager(db.db_path, db=db) backup_id = manager.create_backup(BackupType.FULL)
Restore from backup:
manager.restore_backup(backup_id, "/path/to/restore/location")
List available backups:
backups = manager.list_backups() for backup in backups: print(f"{backup.backup_id}: {backup.created_at}")
- __init__(database_path: str | Path, faiss_index_path: str | Path | None = None, config: BackupConfig | None = None, db: Any | None = None)
- create_backup(backup_type: BackupType = BackupType.FULL, parent_backup_id: str | None = None, backup_id: str | None = None) str
Create a new backup of the database.
- Parameters:
backup_type (BackupType) – Type of backup to create
parent_backup_id (str, optional) – ID of parent backup (required for incremental backups)
backup_id (str, optional) – Custom backup ID. If None, generates a UUID.
- Returns:
Unique backup ID
- Return type:
- Raises:
FileNotFoundError – If database file doesn’t exist
ValueError – If incremental backup requested without parent ID
- list_backups(backup_type: BackupType | None = None) List[BackupMetadata]
List available backups.
- Parameters:
backup_type (BackupType, optional) – Filter by backup type. If None, returns all backups.
- Returns:
List of backup metadata objects
- Return type:
List[BackupMetadata]
- restore_backup(backup_id: str, restore_location: str | Path | None = None, overwrite_existing: bool = False) Path
Restore database from backup.
- Parameters:
- Returns:
Path to restored database directory
- Return type:
Path
- Raises:
FileNotFoundError – If backup file not found
ValueError – If restore would overwrite existing files without permission
- MAX_PATH_LENGTH = 4096
- cleanup_old_backups(retention_days: int | None = None) int
Clean up old backups based on retention policy.
- verify_backup_streaming(backup_id: str, verify_archive_members: bool = True) bool
Verify backup integrity using streaming without full extraction.
- Parameters:
- Returns:
True if backup is valid
- Return type:
Notes
This method provides efficient verification by streaming archive contents rather than extracting to disk. Useful for large backups or when disk space is limited.
- get_backup_info(backup_id: str) BackupMetadata | None
Get detailed information about a backup.
- Parameters:
backup_id (str) – ID of backup to get info for
- Returns:
Backup metadata if found
- Return type:
BackupMetadata or None
- class localvectordb.IncrementalBackupManager(backup_manager: BackupManager)
Bases:
objectSpecialized manager for incremental backups using WAL tracking.
Implements incremental backup functionality by tracking changes in SQLite’s Write-Ahead Log (WAL) and maintaining FAISS index deltas.
- Parameters:
backup_manager (BackupManager) – Parent backup manager instance
- __init__(backup_manager: BackupManager)
- create_incremental_backup(parent_backup_id: str, backup_id: str | None = None) str
Create an incremental backup based on changes since parent backup.
- Parameters:
- Returns:
Unique backup ID for the incremental backup
- Return type:
- Raises:
ValueError – If parent backup not found or WAL mode not enabled
FileNotFoundError – If database files don’t exist
- class localvectordb.PointInTimeRecoveryManager(backup_manager: BackupManager, incremental_manager: IncrementalBackupManager)
Bases:
objectPoint-in-time recovery (PITR) manager for LocalVectorDB.
Provides the ability to restore a database to any point in time within the backup retention window by combining full and incremental backups.
- Parameters:
backup_manager (BackupManager) – Parent backup manager instance
incremental_manager (IncrementalBackupManager) – Incremental backup manager instance
- __init__(backup_manager: BackupManager, incremental_manager: IncrementalBackupManager)
- get_recovery_timeline() List[Dict[str, Any]]
Get the available recovery timeline showing all recovery points.
- Returns:
List of recovery points with timestamps and backup information
- Return type:
List[Dict[str, Any]]
- find_recovery_point(target_timestamp: datetime, tolerance_minutes: int = 60) Dict[str, Any] | None
Find the best recovery point for a target timestamp.
- restore_to_point_in_time(target_timestamp: datetime, restore_location: str | Path, tolerance_minutes: int = 60, dry_run: bool = False) Dict[str, Any]
Restore database to a specific point in time.
- Parameters:
- Returns:
Recovery operation results with status and details
- Return type:
Dict[str, Any]
- validate_recovery_timeline() Dict[str, Any]
Validate the recovery timeline for consistency and completeness.
- Returns:
Validation results with any issues found
- Return type:
Dict[str, Any]
- class localvectordb.Migration(database_path: str | Path)
Bases:
ABCAbstract base class for metadata schema migrations.
All migration classes must inherit from this base class and implement the get_schema_changes() and get_rollback_changes() methods for forward and backward migrations.
This class focuses on metadata schema evolution rather than raw SQL operations, leveraging the existing DatabaseSchema functionality.
- Variables:
- version: str = '0.0.0'
- description: str = 'Base migration'
- abstractmethod get_schema_changes() Dict[str, Any]
Get the schema changes to apply in the forward migration.
- Returns:
Schema changes specification with the following structure:
{ 'new_schema': Dict[str, MetadataField], # Complete new schema 'column_mapping': Dict[str, str], # Rename mappings: old -> new 'drop_columns': bool # Whether to drop unused columns }
- Return type:
Dict[str, Any]
Examples
Add new fields:
return { 'new_schema': { 'user_id': MetadataField(type=MetadataFieldType.TEXT, indexed=True), 'priority': MetadataField(type=MetadataFieldType.INTEGER, default_value=0) } }
Rename and modify fields:
return { 'new_schema': { 'author_name': MetadataField(type=MetadataFieldType.TEXT, indexed=True), 'created_date': MetadataField(type=MetadataFieldType.DATE, indexed=True) }, 'column_mapping': { 'author': 'author_name', 'timestamp': 'created_date' } }
- abstractmethod get_rollback_changes() Dict[str, Any]
Get the schema changes to apply for rollback.
- Returns:
Schema changes specification for rolling back this migration
- Return type:
Dict[str, Any]
- validate_prerequisites(current_schema: Dict[str, MetadataField]) bool
Validate that prerequisites for this migration are met.
- Parameters:
current_schema (Dict[str, MetadataField]) – Current metadata schema
- Returns:
True if prerequisites are met
- Return type:
- class localvectordb.MigrationEngine(database_path: str | Path, migrations_directory: str | Path = './migrations', backup_manager: BackupManager | None = None, auto_backup: bool = True)
Bases:
objectCore database migration management engine.
Handles discovery, validation, execution, and rollback of database migrations. Integrates with the backup system for safety and the versioning system for tracking applied migrations.
- Parameters:
database_path (Union[str, Path]) – Path to the database file
migrations_directory (Union[str, Path], optional) – Directory containing migration scripts. Defaults to “./migrations”
backup_manager (BackupManager, optional) – Backup manager for creating safety backups before migrations
auto_backup (bool) – Whether to automatically create backups before migrations
- __init__(database_path: str | Path, migrations_directory: str | Path = './migrations', backup_manager: BackupManager | None = None, auto_backup: bool = True)
- discover_migrations() Dict[str, MigrationScript]
Discover and load all migration scripts from the migrations directory.
- Returns:
Dictionary mapping version strings to MigrationScript objects
- Return type:
Dict[str, MigrationScript]
- get_migration_order() List[str]
Get the correct order for applying migrations based on dependencies.
- Returns:
List of version strings in the order they should be applied
- Return type:
List[str]
- Raises:
ValueError – If circular dependencies are detected
- get_applied_migrations() List[Dict[str, Any]]
Get list of migrations that have been applied to the database.
- Returns:
List of applied migration records
- Return type:
List[Dict[str, Any]]
- get_pending_migrations(target_version: str | None = None) List[str]
Get list of migrations that need to be applied.
- migrate(target_version: str | None = None, dry_run: bool = False, create_backup: bool | None = None) Dict[str, Any]
Apply pending migrations up to the target version.
- Parameters:
- Returns:
Migration results with status and details
- Return type:
Dict[str, Any]
- rollback(target_version: str, dry_run: bool = False, create_backup: bool | None = None) Dict[str, Any]
Rollback migrations to a target version.
- Parameters:
- Returns:
Rollback results with status and details
- Return type:
Dict[str, Any]
- get_migration_status() Dict[str, Any]
Get comprehensive status of database migrations.
- Returns:
Migration status information
- Return type:
Dict[str, Any]
- class localvectordb.VersionManager(db_path: str | Path)
Bases:
objectManages database version tracking and migration metadata.
Handles SQLite PRAGMA user_version, version metadata in the config table, and migration tracking through the migration_log table.
- Parameters:
db_path (Union[str, Path]) – Path to the SQLite database file
- get_database_version(conn: Connection | None = None) DatabaseVersion
Get the current database version.
Reads from PRAGMA user_version and falls back to config table if needed.
- Parameters:
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- Returns:
Current database version
- Return type:
- set_database_version(version: DatabaseVersion, conn: Connection | None = None) None
Set the database version using both PRAGMA user_version and config table.
- Parameters:
version (DatabaseVersion) – Version to set
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- get_migration_history(conn: Connection | None = None) List[Dict]
Get the history of applied migrations.
- Parameters:
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- Returns:
List of migration records with version, timestamp, and metadata
- Return type:
List[Dict]
- record_migration(version: str, rollback_script: str | None = None, checksum: str | None = None, conn: Connection | None = None) None
Record a completed migration in the migration log.
- Parameters:
version (str) – Version that was migrated to
rollback_script (str, optional) – SQL script for rolling back this migration
checksum (str, optional) – Checksum of the migration for integrity verification
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- needs_migration(target_version: DatabaseVersion | None = None, conn: Connection | None = None) bool
Check if database needs migration to target version.
- Parameters:
target_version (DatabaseVersion, optional) – Target version to check against. Defaults to CURRENT_SCHEMA_VERSION.
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- Returns:
True if migration is needed
- Return type:
- initialize_version_tracking(conn: Connection | None = None) None
Initialize version tracking for a new database.
Sets the database to the current schema version and records initial state.
- Parameters:
conn (sqlite3.Connection, optional) – Database connection to use. If None, creates a new connection.
- class localvectordb.QueryCursor(db: SearchMixin, candidates: List[CursorCandidate], config: CursorConfig, *, ttl_seconds: float = 300.0, default_batch_size: int = 50)
Bases:
objectHolds cached search results with lazy SQLite metadata/content loading.
Lifecycle: 1. Created by
SearchMixin.query_cursor()which runs FAISS/FTS search 2. Consumer callsfetch_batch()or iterates viastream()/__aiter__()3. Each batch triggers a SQLite query for only that batch’s metadata 4. Cursor tracks position and expires after configurable TTL 5. Must be closed explicitly or via context manager- Parameters:
db (LocalVectorDBBase) – Reference to the database for lazy SQLite loading.
candidates (list of CursorCandidate) – Scored candidates from FAISS/FTS, sorted by score descending.
config (CursorConfig) – Query configuration captured at cursor creation time.
ttl_seconds (float) – Time-to-live in seconds (default 300 = 5 minutes).
default_batch_size (int) – Default number of results per batch (default 50).
- __init__(db: SearchMixin, candidates: List[CursorCandidate], config: CursorConfig, *, ttl_seconds: float = 300.0, default_batch_size: int = 50)
- close() None
Close the cursor and release the database reference.
- property closed: bool
- property total_candidates: int
Total number of scored candidates (or documents for document return type).
- property remaining: int
Number of unfetched candidates.
- property is_exhausted: bool
- fetch_batch(batch_size: int | None = None) List[QueryResult]
Fetch the next batch of results, hydrating from SQLite lazily.
- Parameters:
batch_size (int, optional) – Number of results to fetch. Defaults to
default_batch_size.- Returns:
The next batch. Empty list when exhausted.
- Return type:
list of QueryResult
- Raises:
CursorExpiredError – If the cursor has been closed or its TTL has elapsed.
- fetch_all() List[QueryResult]
Fetch all remaining results at once.
- stream(batch_size: int | None = None) Iterator[List[QueryResult]]
Yield batches of results as a sync generator.
- stream_individual(batch_size: int | None = None) Iterator[QueryResult]
Yield individual QueryResult objects.
- async fetch_batch_async(batch_size: int | None = None) List[QueryResult]
Async version of fetch_batch. Hydrates from SQLite using the async pool.
- Parameters:
batch_size (int, optional) – Number of results to fetch. Defaults to
default_batch_size.- Return type:
list of QueryResult
- async fetch_all_async() List[QueryResult]
Fetch all remaining results asynchronously.
- async stream_async(batch_size: int | None = None) AsyncIterator[List[QueryResult]]
Yield batches of results as an async generator.
- async stream_individual_async(batch_size: int | None = None) AsyncIterator[QueryResult]
Yield individual QueryResult objects asynchronously.
- class localvectordb.QueryBuilder(db: BaseVectorDB)
Bases:
objectFluent interface for building complex vector database queries with async support.
This class provides a SQL-like interface for building sophisticated search and filter operations against vector databases.
- __init__(db: BaseVectorDB)
- clone() QueryBuilder
Create a copy of this QueryBuilder for chaining.
- search(query: str, search_type=None, vector_weight=None, score_threshold=None) QueryBuilder
Search the content for query text.
- search_field(field: str, query: str) QueryBuilder
Find records where field contains query.
- filter(field: str | None = None, value: Any = None, **kwargs: Any) QueryBuilder
Add exact filter conditions.
- Parameters:
- Returns:
New QueryBuilder instance with filter conditions added
- Return type:
Examples
Basic filtering:
# Simple equality filter builder.filter("year", 2023) # Multiple fields builder.filter(year=2023, category="AI")
Advanced filtering:
# Range conditions builder.filter("year", gt_=2020, lt_=2024) # Field exists builder.filter("tags", exists_=True)
- Raises:
ValueError – If field is not a string when provided directly
- semantic_filter(field: str, concept: str, threshold: float = 0.8, metric: SimilarityMetric | str = SimilarityMetric.COSINE) QueryBuilder
Add semantic filtering based on conceptual similarity.
metricaccepts either aSimilarityMetricor its string form ("cosine","euclidean","dot"/"dot_product","manhattan"); strings are coerced so the remote/query-builder path works identically to the local one.
- limit(n: int) QueryBuilder
Limit the number of results.
- Parameters:
n (int) – Maximum number of results to return
- Returns:
New QueryBuilder instance with limit applied
- Return type:
- Raises:
ValueError – If n is not positive
- offset(n: int) QueryBuilder
Skip the first n results.
- Parameters:
n (int) – Number of results to skip
- Returns:
New QueryBuilder instance with offset applied
- Return type:
- Raises:
ValueError – If n is negative
- vector(query, score_threshold=None) QueryBuilder
Use vector search.
- keyword(query, score_threshold=None) QueryBuilder
Use keyword search.
- hybrid(query, vector_weight: float = 0.5, score_threshold=None) QueryBuilder
Use hybrid search with specified vector weight.
- semantic_dedup(threshold: float) QueryBuilder
Enable semantic deduplication with similarity threshold.
- documents(scoring_method: Literal['best', 'average', 'frequency_boost'] = 'frequency_boost', scoring_options: dict | None = None) QueryBuilder
Return full documents in results (default).
- chunks() QueryBuilder
Return individual chunks in results with position information.
- sections() QueryBuilder
Return section-level results (requires hierarchical_embeddings).
- search_level(level: Literal['chunks', 'sections', 'documents', 'fused'], section_weight: float | None = None) QueryBuilder
Set the retrieval level (‘chunks’, ‘sections’, ‘documents’, or ‘fused’).
- context(window_size: int = 2) QueryBuilder
Return chunks with context window.
- order_by(field: str, direction: str = 'desc') QueryBuilder
Add ordering by specified field.
- order_by_score(direction: str = 'desc') QueryBuilder
Order results by relevance score.
- clear_ordering() QueryBuilder
Remove all ordering clauses.
- group_by(*fields: str) QueryBuilder
Group results by one or more fields.
- aggregate(field: str, function: Literal['count', 'sum', 'avg', 'min', 'max', 'std', 'var'], alias: str | None = None) QueryBuilder
Add an aggregation function.
- count_by(field: str = '*', alias: str | None = None) QueryBuilder
Count documents/chunks, optionally grouped by field.
- sum_by(field: str, alias: str | None = None) QueryBuilder
Sum numeric values in a field.
- avg_by(field: str, alias: str | None = None) QueryBuilder
Calculate average of numeric values in a field.
- min_by(field: str, alias: str | None = None) QueryBuilder
Find minimum value in a field.
- Parameters:
- Returns:
New QueryBuilder instance with minimum aggregation
- Return type:
- max_by(field: str, alias: str | None = None) QueryBuilder
Find maximum value in a field.
- Parameters:
- Returns:
New QueryBuilder instance with maximum aggregation
- Return type:
- having(field: str, operator: str, value: Any) QueryBuilder
Add HAVING clause for post-aggregation filtering.
Note
Unlike
filter(),havingsupports only the comparison operatorseq,ne,gt,gte,ltandlte. Set/pattern operators such asin,likeorcontainsare not available for HAVING clauses.
- having_count(operator: str, value: int, alias: str = 'count') QueryBuilder
Add HAVING clause for count aggregations.
- rerank(method: str, **config) QueryBuilder
Add reranking configuration for result post-processing.
- rerank_by_recency(date_field: str = 'updated_at', weight: float = 1.0) QueryBuilder
Rerank results by recency (newer documents ranked higher).
- rerank_by_diversity(field: str, weight: float = 1.0) QueryBuilder
Rerank results to promote diversity in specified field.
- rerank_by_model(provider: str, model: str | None = None, top_k: int | None = None, **config) QueryBuilder
Rerank results using a cross-encoder or reranking model.
- Parameters:
- explain(detailed: bool = False, return_plan: bool = False) QueryBuilder | Dict[str, Any]
Enable query explanation or return execution plan directly.
- Parameters:
- Returns:
If return_plan=False: QueryBuilder with explanation enabled If return_plan=True: Execution plan dictionary
- Return type:
Union[QueryBuilder, Dict[str, Any]]
Examples
Traditional usage (returns QueryBuilder with explain enabled):
results = (db.query_builder() .search("machine learning") .explain(detailed=True) .execute())
New usage (returns execution plan directly):
plan = (db.query_builder() .search("machine learning") .explain(detailed=True, return_plan=True)) print(f"Query will execute: {plan['steps']}")
- execute(*, streaming: Literal[False] = False, batch_size: int = 100) List[QueryResult]
- execute(*, streaming: Literal[True], batch_size: int = 100) Iterator[List[QueryResult]]
Execute the query and return results.
- Parameters:
- Returns:
Query results. Returns List when streaming=False, Iterator[List] when streaming=True
- Return type:
Union[List[QueryResult], Iterator[List[QueryResult]]]
- async execute_async(*, streaming: bool = False, batch_size: int = 100) List[QueryResult] | Iterator[List[QueryResult]]
Execute the query asynchronously with native async support.
- Parameters:
- Returns:
Query results. Returns List when streaming=False, Iterator[List] when streaming=True
- Return type:
Union[List[QueryResult], Iterator[List[QueryResult]]]
- cursor(batch_size: int = 50, cursor_ttl: float = 300.0) QueryCursor
Create a QueryCursor for this query configuration.
The cursor performs FAISS/FTS search once and lazily loads content/metadata from SQLite in batches as you iterate.
- Parameters:
- Return type:
- async cursor_async(batch_size: int = 50, cursor_ttl: float = 300.0) QueryCursor
Create a QueryCursor asynchronously.
- Parameters:
- Return type:
- stream(batch_size: int = 100) Iterator[List[QueryResult]]
Stream results in batches using a cursor (single FAISS/FTS search).
- async stream_async(batch_size: int = 100)
Stream results in batches asynchronously using a cursor.
- count() int
Get count of matching results without returning them.
- async count_async() int
Get count of matching results asynchronously.
- get_execution_plan(detailed: bool = False) Dict[str, Any]
Get the execution plan for this query without executing it.
This method allows you to preview how the query will be executed, including the steps, estimated cost, and optimizations that will be applied.
- Parameters:
detailed (bool, optional) – If True, includes additional details like field usage and optimization hints
- Returns:
Execution plan containing: - steps: List of execution steps - estimated_cost: Relative cost estimate - query_type: Type of query (search, filter, hybrid) - optimizations: List of applied optimizations - details: Additional details if detailed=True
- Return type:
Dict[str, Any]
Examples
>>> plan = (db.query_builder() ... .search("machine learning") ... .filter("year", gte=2020) ... .get_execution_plan()) >>> print(f"Query type: {plan['query_type']}") >>> print(f"Steps: {plan['steps']}")
- class localvectordb.ExtractorRegistry
Bases:
objectRegistry for file content extractors.
- classmethod register(extractor: Type[BaseExtractor]) None
Register a new extractor.
- classmethod get_extractor(name: str) BaseExtractor | None
Get an extractor by name.
- classmethod refresh_plugins()
Force re-discovery of plugins (useful for testing)
- classmethod get_extractors_for_file(filename: str, mimetype: str | None = None) List[BaseExtractor]
Get suitable extractors for a file, sorted by priority.
- Parameters:
- Returns:
List of suitable extractors, sorted by priority (highest first)
- Return type:
List[BaseExtractor]
- localvectordb.get_extractor_registry()
Get the global extractor registry.
- localvectordb.get_profile_description(profile_name: str) str
Get human-readable description of a profile.
- localvectordb.is_valid_sqlite_pragma_profile(profile: Literal['balanced', 'fast_ingest', 'read_optimized', 'durable', 'memory_saver']) bool
- localvectordb.get_sqlite_pragma_profile(profile: Literal['balanced', 'fast_ingest', 'read_optimized', 'durable', 'memory_saver'], *, default: Literal['balanced', 'fast_ingest', 'read_optimized', 'durable', 'memory_saver'] | None = None) SQLitePragmaProfile | None
- class localvectordb.FactChecker(databases: LocalVectorDB | list[LocalVectorDB], llm: LLMProvider | Any, model: str | None = None, similarity_threshold: float = 0.3, min_grounding_score: float = 0.7, search_type: str = 'hybrid', top_k: int = 5, max_concurrent: int = 5)
Bases:
objectFact-check LLM-generated text against one or more LocalVectorDB instances.
- Parameters:
databases – One or more
LocalVectorDBinstances to search for evidence.llm – An Anthropic, OpenAI, or Google GenAI client, or any object implementing the
LLMProviderprotocol.model – Model name passed to the LLM provider for claim extraction and polarity classification. Defaults are provider-specific (Haiku for Anthropic, gpt-4o-mini for OpenAI, gemini-2.0-flash for Gemini).
similarity_threshold – Minimum similarity score for a retrieved chunk to be considered relevant.
min_grounding_score – Minimum polarity confidence for a claim to count as grounded.
search_type – Search mode used when querying the databases (
"vector","keyword", or"hybrid").top_k – Number of chunks to retrieve per claim per database.
max_concurrent – Maximum number of claims to process concurrently.
- __init__(databases: LocalVectorDB | list[LocalVectorDB], llm: LLMProvider | Any, model: str | None = None, similarity_threshold: float = 0.3, min_grounding_score: float = 0.7, search_type: str = 'hybrid', top_k: int = 5, max_concurrent: int = 5) None
- async check_async(text: str, sources: list[str] | None = None) FactCheckResult
Fact-check text asynchronously.
- Parameters:
text – The LLM-generated text to verify.
sources – Optional list of document IDs that were used to generate text. When provided, these are searched first; the full database is only queried when no supporting evidence is found or a contradiction is detected.
- check(text: str, sources: list[str] | None = None) FactCheckResult
Synchronous wrapper around
check_async().
- class localvectordb.FactCheckResult(claims: list[ClaimResult] = <factory>, overall_score: float = 0.0, has_contradictions: bool = False, citation_text: str = '', annotated_text: str | None = None)
Bases:
objectAggregate result of fact-checking a text against one or more databases.
- claims: list[ClaimResult]
- overall_score: float = 0.0
- has_contradictions: bool = False
- citation_text: str = ''
- class localvectordb.ClaimResult(claim: str, grounded: bool, confidence: float, source_id: str | None = None, source_excerpt: str | None = None, contradiction: bool = False, polarity: Polarity | None = None, similarity: float | None = None, original_sentence: str | None = None, database_name: str | None = None)
Bases:
objectResult of checking a single factual claim against sources.
- claim: str
- grounded: bool
- confidence: float
- contradiction: bool = False
- class localvectordb.Polarity(*values)
-
Relationship between a claim and a source chunk.
- SUPPORTS = 'supports'
- CONTRADICTS = 'contradicts'
- UNRELATED = 'unrelated'
Subpackages
- localvectordb.database package
LocalVectorDBLocalVectorDB.__init__()LocalVectorDB.analyze_system_resources()LocalVectorDB.auto_tune()LocalVectorDB.batch_sizeLocalVectorDB.checkpoint_if_wal_large()LocalVectorDB.chunk_overlapLocalVectorDB.chunk_similarity_matrix()LocalVectorDB.chunk_sizeLocalVectorDB.chunking_methodLocalVectorDB.close()LocalVectorDB.close_async()LocalVectorDB.closedLocalVectorDB.compare_documents()LocalVectorDB.compare_documents_async()LocalVectorDB.compare_documents_detailed()LocalVectorDB.compare_documents_detailed_async()LocalVectorDB.count()LocalVectorDB.count_async()LocalVectorDB.delete()LocalVectorDB.delete_async()LocalVectorDB.embedding_dimensionLocalVectorDB.embedding_modelLocalVectorDB.embedding_providerLocalVectorDB.exists()LocalVectorDB.exists_async()LocalVectorDB.filter()LocalVectorDB.filter_async()LocalVectorDB.fts_enabledLocalVectorDB.get()LocalVectorDB.get_async()LocalVectorDB.get_async_pool_stats()LocalVectorDB.get_chunk_embeddings()LocalVectorDB.get_chunks()LocalVectorDB.get_metadata_schema_info()LocalVectorDB.get_metadata_schema_info_async()LocalVectorDB.get_sqlite_tuning()LocalVectorDB.get_stats()LocalVectorDB.get_stats_async()LocalVectorDB.hierarchical_embeddingsLocalVectorDB.insert()LocalVectorDB.insert_async()LocalVectorDB.insert_from_chunks()LocalVectorDB.insert_from_chunks_async()LocalVectorDB.insert_from_file()LocalVectorDB.insert_from_file_async()LocalVectorDB.is_memory_onlyLocalVectorDB.list_sqlite_profiles()LocalVectorDB.metadata_schemaLocalVectorDB.nearest_neighbors()LocalVectorDB.nearest_neighbors_async()LocalVectorDB.pairwise_similarity_matrix()LocalVectorDB.pairwise_similarity_matrix_async()LocalVectorDB.patch()LocalVectorDB.patch_async()LocalVectorDB.ping()LocalVectorDB.query()LocalVectorDB.query_async()LocalVectorDB.query_builder()LocalVectorDB.query_cursor()LocalVectorDB.query_cursor_async()LocalVectorDB.query_multi_column()LocalVectorDB.query_multi_column_async()LocalVectorDB.query_stream()LocalVectorDB.query_stream_async()LocalVectorDB.rebuild_hierarchical_embeddings()LocalVectorDB.repair()LocalVectorDB.save()LocalVectorDB.save_async()LocalVectorDB.section_vector_strategyLocalVectorDB.set_sqlite_tuning()LocalVectorDB.sqlite_checkpoint()LocalVectorDB.sqlite_incremental_vacuum()LocalVectorDB.sqlite_optimize()LocalVectorDB.sqlite_vacuum()LocalVectorDB.update()LocalVectorDB.update_async()LocalVectorDB.update_metadata_schema()LocalVectorDB.update_metadata_schema_async()LocalVectorDB.upsert()LocalVectorDB.upsert_async()LocalVectorDB.upsert_from_chunks()LocalVectorDB.upsert_from_chunks_async()LocalVectorDB.upsert_from_file()LocalVectorDB.upsert_from_file_async()LocalVectorDB.visualize_chord()LocalVectorDB.visualize_documents()LocalVectorDB.visualize_queries()LocalVectorDB.visualize_synteny()LocalVectorDB.connection_poolLocalVectorDB.async_connection_poolLocalVectorDB.indexLocalVectorDB.schemaLocalVectorDB.chunkerLocalVectorDB.pipeline_worker_timeoutLocalVectorDB.section_indexLocalVectorDB.document_index
BaseVectorDBBaseVectorDB.upsert()BaseVectorDB.insert()BaseVectorDB.get()BaseVectorDB.exists()BaseVectorDB.count()BaseVectorDB.delete()BaseVectorDB.update()BaseVectorDB.patch()BaseVectorDB.query()BaseVectorDB.query_cursor()BaseVectorDB.query_cursor_async()BaseVectorDB.filter()BaseVectorDB.embedding_modelBaseVectorDB.embedding_providerBaseVectorDB.embedding_dimensionBaseVectorDB.chunk_sizeBaseVectorDB.chunk_overlapBaseVectorDB.chunking_methodBaseVectorDB.fts_enabledBaseVectorDB.metadata_schemaBaseVectorDB.get_stats()BaseVectorDB.get_stats_async()BaseVectorDB.closedBaseVectorDB.update_metadata_schema()BaseVectorDB.get_metadata_schema_info()BaseVectorDB.save()BaseVectorDB.close()BaseVectorDB.query_builder()BaseVectorDB.ping()BaseVectorDB.upsert_from_chunks()BaseVectorDB.insert_from_chunks()BaseVectorDB.upsert_from_file()BaseVectorDB.insert_from_file()BaseVectorDB.upsert_async()BaseVectorDB.insert_async()BaseVectorDB.upsert_from_chunks_async()BaseVectorDB.insert_from_chunks_async()BaseVectorDB.upsert_from_file_async()BaseVectorDB.insert_from_file_async()BaseVectorDB.get_async()BaseVectorDB.exists_async()BaseVectorDB.delete_async()BaseVectorDB.count_async()BaseVectorDB.update_async()BaseVectorDB.patch_async()BaseVectorDB.query_async()BaseVectorDB.filter_async()BaseVectorDB.save_async()BaseVectorDB.close_async()BaseVectorDB.update_metadata_schema_async()BaseVectorDB.get_metadata_schema_info_async()BaseVectorDB.get_chunk_embeddings()BaseVectorDB.compare_documents()BaseVectorDB.compare_documents_async()BaseVectorDB.compare_documents_detailed()BaseVectorDB.compare_documents_detailed_async()BaseVectorDB.nearest_neighbors()BaseVectorDB.nearest_neighbors_async()BaseVectorDB.pairwise_similarity_matrix()BaseVectorDB.pairwise_similarity_matrix_async()BaseVectorDB.get_chunks()BaseVectorDB.__init__()
TuningMixinTuningMixin.get_sqlite_tuning()TuningMixin.set_sqlite_tuning()TuningMixin.sqlite_checkpoint()TuningMixin.sqlite_optimize()TuningMixin.sqlite_vacuum()TuningMixin.sqlite_incremental_vacuum()TuningMixin.list_sqlite_profiles()TuningMixin.analyze_system_resources()TuningMixin.auto_tune()TuningMixin.checkpoint_if_wal_large()TuningMixin.__init__()
RepairReportRepairReport.dry_runRepairReport.duplicate_idsRepairReport.orphan_vectorsRepairReport.dangling_rowsRepairReport.reconstructedRepairReport.reembeddedRepairReport.droppedRepairReport.base_index_typeRepairReport.sections_rebuiltRepairReport.documents_rebuiltRepairReport.healthyRepairReport.summary()RepairReport.__init__()
open_for_repair()- Submodules
- localvectordb.extractors package
ZipBombErrorvalidate_zip_safety()ExtractionResultBaseExtractorBaseExtractor.__init__()BaseExtractor.availableBaseExtractor.max_file_size_bytesBaseExtractor.supported_extensionsBaseExtractor.supported_mimetypesBaseExtractor.required_packagesBaseExtractor.priorityBaseExtractor.metadata_schemaBaseExtractor.can_extract()BaseExtractor.extract_text()BaseExtractor.get_info()
ExtractorRegistryget_extractor_registry()get_supported_formats()- Submodules
- localvectordb.validation package
- localvectordb.visualization package
reduce_dimensions()cluster_embeddings()find_optimal_clusters()plot_embedding_map()plot_similarity_matrix()plot_clusters()plot_similarity_graph()build_similarity_graph()plot_synteny()plot_chord()plot_embedding_map_interactive()plot_similarity_matrix_interactive()plot_clusters_interactive()plot_synteny_interactive()plot_chord_interactive()EmbeddingProjectionClusterResultQueryOverlay- Submodules
Submodules
- localvectordb.backup module
BackupTypeCompressionAlgorithmBackupMetadataBackupConfigBackupManagerBackupManager.__init__()BackupManager.create_backup()BackupManager.list_backups()BackupManager.restore_backup()BackupManager.MAX_PATH_LENGTHBackupManager.delete_backup()BackupManager.cleanup_old_backups()BackupManager.verify_backup_streaming()BackupManager.verify_backup()BackupManager.get_backup_info()
IncrementalBackupManagerPointInTimeRecoveryManagerPointInTimeRecoveryManager.__init__()PointInTimeRecoveryManager.get_recovery_timeline()PointInTimeRecoveryManager.find_recovery_point()PointInTimeRecoveryManager.restore_to_point_in_time()PointInTimeRecoveryManager.validate_recovery_timeline()PointInTimeRecoveryManager.cleanup_recovery_timeline()PointInTimeRecoveryManager.get_recovery_recommendations()
- localvectordb.chunking module
- localvectordb.client module
RemoteQueryBuilderRemoteQueryBuilder.__init__()RemoteQueryBuilder.clone()RemoteQueryBuilder.search()RemoteQueryBuilder.search_field()RemoteQueryBuilder.filter()RemoteQueryBuilder.semantic_filter()RemoteQueryBuilder.vector()RemoteQueryBuilder.keyword()RemoteQueryBuilder.hybrid()RemoteQueryBuilder.documents()RemoteQueryBuilder.chunks()RemoteQueryBuilder.sections()RemoteQueryBuilder.context()RemoteQueryBuilder.search_level()RemoteQueryBuilder.semantic_dedup()RemoteQueryBuilder.order_by()RemoteQueryBuilder.order_by_score()RemoteQueryBuilder.clear_ordering()RemoteQueryBuilder.limit()RemoteQueryBuilder.offset()RemoteQueryBuilder.group_by()RemoteQueryBuilder.aggregate()RemoteQueryBuilder.count_by()RemoteQueryBuilder.sum_by()RemoteQueryBuilder.avg_by()RemoteQueryBuilder.min_by()RemoteQueryBuilder.max_by()RemoteQueryBuilder.with_search_type()RemoteQueryBuilder.with_vector_weight()RemoteQueryBuilder.with_return_type()RemoteQueryBuilder.to_dict()RemoteQueryBuilder.execute()RemoteQueryBuilder.execute_async()RemoteQueryBuilder.count()RemoteQueryBuilder.count_async()
RemoteVectorDBRemoteVectorDB.__init__()RemoteVectorDB.embedding_providerRemoteVectorDB.metadata_schemaRemoteVectorDB.embedding_modelRemoteVectorDB.embedding_dimensionRemoteVectorDB.chunk_sizeRemoteVectorDB.chunk_overlapRemoteVectorDB.chunking_methodRemoteVectorDB.fts_enabledRemoteVectorDB.get_stats()RemoteVectorDB.upsert()RemoteVectorDB.insert()RemoteVectorDB.count()RemoteVectorDB.upsert_from_file()RemoteVectorDB.insert_from_file()RemoteVectorDB.upsert_from_chunks()RemoteVectorDB.insert_from_chunks()RemoteVectorDB.get()RemoteVectorDB.get_chunk_embeddings()RemoteVectorDB.exists()RemoteVectorDB.delete()RemoteVectorDB.update()RemoteVectorDB.patch()RemoteVectorDB.query()RemoteVectorDB.query_multi_column()RemoteVectorDB.filter()RemoteVectorDB.query_builder()RemoteVectorDB.save()RemoteVectorDB.update_metadata_schema()RemoteVectorDB.get_metadata_schema_info()RemoteVectorDB.healthyRemoteVectorDB.closedRemoteVectorDB.ping()RemoteVectorDB.close()RemoteVectorDB.database_exists()RemoteVectorDB.get_stats_async()RemoteVectorDB.upsert_async()RemoteVectorDB.insert_async()RemoteVectorDB.upsert_from_file_async()RemoteVectorDB.insert_from_file_async()RemoteVectorDB.upsert_from_chunks_async()RemoteVectorDB.insert_from_chunks_async()RemoteVectorDB.get_async()RemoteVectorDB.exists_async()RemoteVectorDB.delete_async()RemoteVectorDB.count_async()RemoteVectorDB.update_async()RemoteVectorDB.patch_async()RemoteVectorDB.query_async()RemoteVectorDB.query_multi_column_async()RemoteVectorDB.filter_async()RemoteVectorDB.save_async()RemoteVectorDB.close_async()RemoteVectorDB.update_metadata_schema_async()RemoteVectorDB.get_metadata_schema_info_async()RemoteVectorDB.get_sqlite_tuning()RemoteVectorDB.set_sqlite_tuning()RemoteVectorDB.auto_tune()RemoteVectorDB.sqlite_checkpoint()RemoteVectorDB.sqlite_optimize()RemoteVectorDB.sqlite_vacuum()RemoteVectorDB.sqlite_incremental_vacuum()RemoteVectorDB.analyze_system_resources()RemoteVectorDB.checkpoint_if_wal_large()RemoteVectorDB.query_stream()RemoteVectorDB.query_stream_async()RemoteVectorDB.compare_documents()RemoteVectorDB.compare_documents_async()RemoteVectorDB.compare_documents_detailed()RemoteVectorDB.compare_documents_detailed_async()RemoteVectorDB.nearest_neighbors()RemoteVectorDB.nearest_neighbors_async()RemoteVectorDB.pairwise_similarity_matrix()RemoteVectorDB.pairwise_similarity_matrix_async()
- localvectordb.core module
DocumentScoringMethodMetadataFieldTypeMetadataFieldChunkPositionChunkSectionBoundarySectionDocumentQueryResultChunkAlignmentDocumentComparisonResultDocumentComparisonResult.doc_id_1DocumentComparisonResult.doc_id_2DocumentComparisonResult.overall_similarityDocumentComparisonResult.chunk_alignmentsDocumentComparisonResult.matched_ratio_1DocumentComparisonResult.matched_ratio_2DocumentComparisonResult.unmatched_chunks_1DocumentComparisonResult.unmatched_chunks_2DocumentComparisonResult.to_dict()DocumentComparisonResult.from_dict()DocumentComparisonResult.__init__()
DocumentSimilarityMatrixChunkSimilarityMatrix
- localvectordb.cursor module
CursorCandidateCursorConfigCursorConfig.search_typeCursorConfig.return_typeCursorConfig.search_levelCursorConfig.score_thresholdCursorConfig.filtersCursorConfig.vector_weightCursorConfig.context_windowCursorConfig.semantic_dedup_thresholdCursorConfig.document_scoring_methodCursorConfig.document_scoring_optionsCursorConfig.total_kCursorConfig.context_unitCursorConfig.context_truncateCursorConfig.__init__()
DocumentCandidateQueryCursorQueryCursor.__init__()QueryCursor.close()QueryCursor.closedQueryCursor.total_candidatesQueryCursor.remainingQueryCursor.is_exhaustedQueryCursor.fetch_batch()QueryCursor.fetch_all()QueryCursor.stream()QueryCursor.stream_individual()QueryCursor.fetch_batch_async()QueryCursor.fetch_all_async()QueryCursor.stream_async()QueryCursor.stream_individual_async()
- localvectordb.embeddings module
EmbeddingProviderHTTPEmbeddingProviderOllamaEmbeddingsOpenAIEmbeddingsGoogleEmbeddingsJinaEmbeddingsSentenceTransformerEmbeddingsHuggingFaceInferenceEmbeddingsHuggingFaceLocalEmbeddingsMockEmbeddingsEmbeddingRegistrycreate_embedding_provider()list_providers()embed_texts()embed_texts_sync()
- localvectordb.exceptions module
BaseLocalVectorDBExceptionDatabaseErrorDatabaseNotFoundErrorMetadataFilterErrorDuplicateDocumentIDErrorIndexIntegrityErrorUnsupportedIndexOperationErrorDocumentNotFoundErrorPatchConflictErrorPatchErrorEmbeddingErrorOllamaNotFoundErrorConfigurationErrorValidationErrorConnectionPoolErrorRerankerErrorCursorErrorCursorExpiredErrorCursorExhaustedError
- localvectordb.factory module
- localvectordb.migration module
serialize_metadata_field()deserialize_metadata_field()serialize_schema_changes()deserialize_schema_changes()MigrationMigrationScriptMigrationEngineMigrationEngine.__init__()MigrationEngine.discover_migrations()MigrationEngine.get_migration_order()MigrationEngine.get_applied_migrations()MigrationEngine.get_pending_migrations()MigrationEngine.migrate()MigrationEngine.rollback()MigrationEngine.get_migration_status()MigrationEngine.create_migration_template()
- localvectordb.patching module
- localvectordb.query_builder module
- Core Features
SimilarityMetricSearchClauseSemanticFilterAggregationClauseQueryBuilderQueryBuilder.__init__()QueryBuilder.clone()QueryBuilder.search()QueryBuilder.search_field()QueryBuilder.filter()QueryBuilder.semantic_filter()QueryBuilder.limit()QueryBuilder.offset()QueryBuilder.vector()QueryBuilder.keyword()QueryBuilder.hybrid()QueryBuilder.semantic_dedup()QueryBuilder.documents()QueryBuilder.chunks()QueryBuilder.sections()QueryBuilder.search_level()QueryBuilder.context()QueryBuilder.order_by()QueryBuilder.order_by_score()QueryBuilder.clear_ordering()QueryBuilder.group_by()QueryBuilder.aggregate()QueryBuilder.count_by()QueryBuilder.sum_by()QueryBuilder.avg_by()QueryBuilder.min_by()QueryBuilder.max_by()QueryBuilder.having()QueryBuilder.having_count()QueryBuilder.rerank()QueryBuilder.rerank_by_recency()QueryBuilder.rerank_by_diversity()QueryBuilder.rerank_by_model()QueryBuilder.explain()QueryBuilder.validate()QueryBuilder.debug_info()QueryBuilder.execute()QueryBuilder.execute_async()QueryBuilder.cursor()QueryBuilder.cursor_async()QueryBuilder.stream()QueryBuilder.stream_async()QueryBuilder.count()QueryBuilder.count_async()QueryBuilder.get_execution_plan()QueryBuilder.get_execution_plan_async()
QueryExecutorAsyncQueryExecutor
- localvectordb.reranking module
- localvectordb.section_detection module
- localvectordb.section_metadata module
- localvectordb.sqlite_tuning module
- localvectordb.utils module
- localvectordb.versioning module