In-memory vector store with cosine similarity search
Project description
philiprehberger-embedding-store
In-memory vector store with cosine 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}")
# Filter by metadata
results = store.search(query, top_k=10, filter=lambda m: m["category"] == "tech")
# Minimum score threshold
results = store.search(query, min_score=0.7)
# Persistence
store.save("vectors.json")
loaded = VectorStore.load("vectors.json")
# Batch operations
store.add_many([("id1", emb1, meta1), ("id2", emb2, meta2)])
Distance metrics
"cosine"(default) — cosine similarity"dot"— dot product
API
| Function / Class | Description |
|---|---|
VectorStore(dimensions) |
Create a new vector store with the given dimensionality |
add(id, embedding, metadata?) |
Add a vector |
add_many(items) |
Batch add |
search(query, top_k?, metric?, filter?, min_score?) |
Similarity search |
get(id) |
Get entry by ID |
delete(id) |
Delete entry |
update_metadata(id, metadata) |
Update metadata |
save(path) |
Save to JSON |
VectorStore.load(path) |
Load from JSON |
clear() |
Remove all entries |
ids() |
List all IDs |
len(store) |
Number of entries |
id in store |
Check if ID exists |
store.size |
Number of entries (property) |
Development
pip install -e .
python -m pytest tests/ -v
License
MIT
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.2.2.tar.gz.
File metadata
- Download URL: philiprehberger_embedding_store-0.2.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17dd66b16293a5ebb9307a5f377e63f8fee9aa685a2527be97cd31d993a13d4
|
|
| MD5 |
efe8b6118f18d1881483f65f9ec0f9ad
|
|
| BLAKE2b-256 |
952c862e9cacac4471b78c85382d6549ee378e7a1bbee35ec548581892d90366
|
File details
Details for the file philiprehberger_embedding_store-0.2.2-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_embedding_store-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.5 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 |
1e7d3210705b7bb3c6be401da8f407c29814c79c09cdd2d3fffe288ec010d1db
|
|
| MD5 |
775c8438d1a63b084be485d33317cd3a
|
|
| BLAKE2b-256 |
89850ba5477fd42d239c534fea64e9e78573bccfcc847a4c5598ce0bcb7f1aff
|