Lightweight local vector database with persistence to disk, supporting multiple similarity metrics and easy-to-use API.
Project description
microvector
Lightweight local vector database with persistence to disk, supporting multiple similarity metrics and an easy-to-use API.
A refactor and repackaging of HyperDB optimized for CPU-only environments with improved type safety and developer experience.
Features
- 🚀 Simple API: Clean, intuitive interface with just two main methods:
save()andsearch() - 💾 Persistent Storage: Automatically caches vector stores to
.pickle.gzfiles - 🔍 Multiple Similarity Metrics: Choose from cosine, dot product, Euclidean, or Derrida distance
- 🎯 Type Safe: Full type annotations with strict pyright compliance
- ⚡ CPU Optimized: Designed for CPU-only environments (no CUDA required)
- 🔄 Flexible Caching: Use persistent stores or create temporary in-memory collections
- 📦 Easy Installation: One-command setup with automatic PyTorch CPU configuration
Installation
pip install microvector
Or for development:
git clone https://github.com/loganpowell/microvector.git
cd microvector
uv sync
Quick Start
from microvector import Client
# Initialize the client
client = Client()
# Save a collection with automatic persistence
client.save(
partition_name="my_documents",
collection=[
{"text": "Python is a popular programming language", "category": "tech"},
{"text": "Machine learning models learn from data", "category": "ai"},
{"text": "The quick brown fox jumps over the lazy dog", "category": "example"},
]
)
# Search the persisted collection
results = client.search(
term="artificial intelligence and ML",
partition_name="my_documents",
key="text",
top_k=5
)
for result in results:
print(f"Score: {result['similarity_score']:.4f} - {result['text']}")
API Reference
Client
The main interface for all vector operations.
Client(
cache_models: str = "./.cached_models",
cache_vectors: str = "./.vector_cache",
embedding_model: str = "avsolatorio/GIST-small-Embedding-v0"
)
Parameters:
cache_models: Directory for caching downloaded embedding modelscache_vectors: Directory for persisting vector storesembedding_model: HuggingFace model name for generating embeddings
save()
Save a collection to a persistent vector store.
client.save(
partition_name: str,
collection: list[dict[str, Any]],
key: str = "text",
algo: str = "cosine"
) -> dict[str, Any]
Parameters:
partition_name: Unique identifier for this vector storecollection: List of documents (dictionaries) to vectorizekey: Field name to use for embedding (default: "text")algo: Similarity metric -"cosine","dot","euclidean", or"derrida"
Returns:
{
"status": "success",
"partition": "my_documents",
"documents_saved": 42,
"key": "text",
"algorithm": "cosine"
}
Example:
result = client.save(
partition_name="products",
collection=[
{"description": "Wireless headphones", "price": 99.99},
{"description": "Smart watch", "price": 299.99},
],
key="description",
algo="cosine"
)
search()
Search a vector store with semantic similarity.
client.search(
term: str,
partition_name: str,
key: str = "text",
top_k: int = 5,
collection: Optional[list[dict[str, Any]]] = None,
cache: bool = True,
algo: str = "cosine"
) -> list[dict[str, Any]]
Parameters:
term: Search query stringpartition_name: Name of the vector store to querykey: property within each item in the collection to search against (vectorized field)top_k: Maximum number of results to returncollection: Optional temporary collection (for non-persistent search)cache: If True, persist the collection; if False, keep in-memory onlyalgo: Similarity metric to use
Returns: List of documents with similarity scores
[
{
"text": "Machine learning is awesome",
"category": "ai",
"similarity_score": 0.923
},
...
]
Example - Search existing store:
results = client.search(
term="laptop computers",
partition_name="products",
key="description",
top_k=3
)
Example - Temporary search (no persistence):
results = client.search(
term="budget phones",
partition_name="temp_search",
key="description",
top_k=5,
collection=[
{"description": "iPhone 15 Pro", "price": 999},
{"description": "Samsung Galaxy S24", "price": 899},
],
cache=False # Don't save to disk
)
Similarity Algorithms
| Algorithm | Best For | Range |
|---|---|---|
cosine |
General text similarity (default) | 0-1 (higher is more similar) |
dot |
When magnitude matters | Unbounded |
euclidean |
Spatial distance | 0-∞ (lower is more similar) |
derrida |
Experimental alternative distance | 0-∞ (lower is more similar) |
Advanced Usage
Custom Embedding Models
Use any HuggingFace sentence-transformer model:
client = Client(
embedding_model="intfloat/e5-small-v2"
)
Nested Key Paths
Access nested fields using dot notation:
collection = [
{
"product": {
"name": "Laptop",
"specs": {"cpu": "Intel i7"}
}
}
]
client.save(
partition_name="products",
collection=collection,
key="product.name"
)
Working with Multiple Partitions
Organize different datasets in separate partitions:
# Save different content types
client.save("news_articles", news_data, key="content")
client.save("product_reviews", review_data, key="review_text")
client.save("support_tickets", tickets, key="description")
# Search each independently
news_results = client.search("economy", "news_articles", key="content")
review_results = client.search("quality", "product_reviews", key="review_text")
Development Setup
This project uses uv for dependency management and automatically configures CPU-only PyTorch.
Quick Start
-
Install dependencies:
uv sync -
Verify setup:
uv run python setup_dev.py
-
Run tests:
uv run pytest
-
Type checking:
uv run pyright
What Gets Installed
- PyTorch (CPU-only): Automatically from PyTorch CPU index
- Transformers: HuggingFace transformers library
- Sentence Transformers: For embedding generation
- NumPy: Numerical computing
No special flags or manual PyTorch installation needed - just uv sync and go!
Performance Tips
- Reuse Client instances - Model loading is expensive
- Use persistent caching - Vector computation is cached automatically
- Batch your saves - Save collections together when possible
- Choose the right algorithm - Cosine is fastest for most use cases
- Adjust top_k - Lower values are faster
Architecture
microvector/
├── main.py # Client API
├── store.py # Vector storage and similarity search
├── cache.py # Persistence layer
├── embed.py # Embedding generation
├── algos.py # Similarity algorithms
└── utils.py # Helper functions
License
MIT License - see LICENSE file for details.
Credits
Based on HyperDB by John Dagdelen. Refactored and maintained by Logan Powell.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file microvector-0.1.23.tar.gz.
File metadata
- Download URL: microvector-0.1.23.tar.gz
- Upload date:
- Size: 128.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
707d314641ef25f0a628af5a9c94640836c6b9de81c02b9fb1be7d3ea93c57a3
|
|
| MD5 |
281407da447919b0675a3d636ccce914
|
|
| BLAKE2b-256 |
648b7db62d6d2b4984d1c9afdfc7423d1147f0c62310707ba470ca854e547108
|
Provenance
The following attestation bundles were made for microvector-0.1.23.tar.gz:
Publisher:
publish.yml on loganpowell/microvector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
microvector-0.1.23.tar.gz -
Subject digest:
707d314641ef25f0a628af5a9c94640836c6b9de81c02b9fb1be7d3ea93c57a3 - Sigstore transparency entry: 634412487
- Sigstore integration time:
-
Permalink:
loganpowell/microvector@2f3e1b8078acdcd5a82b7af84b44e0c54015a454 -
Branch / Tag:
refs/tags/v0.1.23 - Owner: https://github.com/loganpowell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f3e1b8078acdcd5a82b7af84b44e0c54015a454 -
Trigger Event:
release
-
Statement type:
File details
Details for the file microvector-0.1.23-py3-none-any.whl.
File metadata
- Download URL: microvector-0.1.23-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f6ab813473e1cff884d715e676a4397752136c82e249660610115c457af225f
|
|
| MD5 |
209d7956ede28d368b016d9039b2c600
|
|
| BLAKE2b-256 |
9563d5d31de88892d75cffc5cb2c96edd3cab78cd1fba818da5ba519bb8cd33e
|
Provenance
The following attestation bundles were made for microvector-0.1.23-py3-none-any.whl:
Publisher:
publish.yml on loganpowell/microvector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
microvector-0.1.23-py3-none-any.whl -
Subject digest:
7f6ab813473e1cff884d715e676a4397752136c82e249660610115c457af225f - Sigstore transparency entry: 634412490
- Sigstore integration time:
-
Permalink:
loganpowell/microvector@2f3e1b8078acdcd5a82b7af84b44e0c54015a454 -
Branch / Tag:
refs/tags/v0.1.23 - Owner: https://github.com/loganpowell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2f3e1b8078acdcd5a82b7af84b44e0c54015a454 -
Trigger Event:
release
-
Statement type: