In-memory vector store with multi-metric similarity search.
Project description
philiprehberger-embedding-store
In-memory vector store with multi-metric similarity search.
Installation
pip install philiprehberger-embedding-store
Usage
from philiprehberger_embedding_store import VectorStore
store = VectorStore(dimensions=1536)
# Add vectors with metadata
store.add("doc1", embedding=[0.1, 0.2, ...], metadata={"title": "First doc"})
store.add("doc2", embedding=[0.3, 0.1, ...], metadata={"title": "Second doc"})
# Search by similarity
results = store.search(query_embedding=[0.15, 0.18, ...], top_k=5)
for result in results:
print(f"{result.id}: score={result.score:.3f}, {result.metadata}")
Distance metrics
Choose a metric per store or override per search call:
from philiprehberger_embedding_store import VectorStore
# Set default metric at store level
store = VectorStore(dimensions=128, metric="euclidean")
results = store.search(query, top_k=5)
# Override metric for a single search
results = store.search(query, top_k=5, metric="manhattan")
Supported metrics: "cosine" (default), "dot", "euclidean", "manhattan".
Metadata filtering
from philiprehberger_embedding_store import VectorStore
store = VectorStore()
store.add("d1", [1.0, 0.0], {"category": "docs", "lang": "en"})
store.add("d2", [0.9, 0.1], {"category": "code", "lang": "en"})
# Filter by single field
results = store.search(query, filter=lambda m: m["category"] == "docs")
# Filter by multiple conditions
results = store.search(
query,
filter=lambda m: m["category"] == "docs" and m["lang"] == "en",
)
Batch operations
from philiprehberger_embedding_store import VectorStore
store = VectorStore()
# Add many vectors at once
store.add_many([
("id1", [0.1, 0.2], {"label": "first"}),
("id2", [0.3, 0.4], {"label": "second"}),
])
# Search with multiple queries at once
all_results = store.search_many(
[query_embedding_1, query_embedding_2],
top_k=5,
)
Persistence
from philiprehberger_embedding_store import VectorStore
store = VectorStore()
store.add("doc1", [0.1, 0.2], {"title": "Example"})
# Save to disk
store.save("vectors.json")
# Load from disk
loaded = VectorStore.load("vectors.json")
Store management
from philiprehberger_embedding_store import VectorStore
store = VectorStore()
store.add("a", [1.0, 0.0])
store.remove("a") # Remove by ID
store.clear() # Remove all entries
API
| Function / Class | Description |
|---|---|
VectorStore(dimensions, metric?) |
Create a store with optional dimensionality and metric |
add(id, embedding, metadata?) |
Add a vector with optional metadata |
add_many(items) |
Batch add multiple vectors |
search(query, top_k?, metric?, filter?, min_score?) |
Similarity search |
search_many(queries, top_k?, metric?, filter?, min_score?) |
Batch similarity search |
get(id) |
Get entry by ID |
delete(id) |
Delete entry by ID |
remove(id) |
Remove entry by ID (alias for delete) |
update_metadata(id, metadata) |
Update metadata for an entry |
save(path) |
Save store to JSON file |
VectorStore.load(path) |
Load store from JSON file |
clear() |
Remove all entries |
ids() |
List all stored IDs |
len(store) |
Number of entries |
id in store |
Check if ID exists |
store.size |
Number of entries (property) |
store.metric |
Current distance metric (property) |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
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 philiprehberger_embedding_store-0.3.0.tar.gz.
File metadata
- Download URL: philiprehberger_embedding_store-0.3.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dde7235f3b7926a2a2dfe550a7a45153b92eddf0744726912c5cf46f4b5138c
|
|
| MD5 |
70447741ea126404f0a5c6f521cae047
|
|
| BLAKE2b-256 |
9a745677ac31c974696c223d2dab9026e15062f370ab848349430dbecc351c42
|
File details
Details for the file philiprehberger_embedding_store-0.3.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_embedding_store-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eda4622a9fe8984ab16cb98766062e7e394e61e9079a9218f0f52b31e70a16d4
|
|
| MD5 |
4e46c43ba3ba016bdd7b27cf9ca2085e
|
|
| BLAKE2b-256 |
3d076f5f960e136da7f457c6426e221c9088ba67f2e3907c6452b29b51cf71ba
|