Skip to main content

In-memory vector store with multi-metric similarity search.

Project description

philiprehberger-embedding-store

Tests PyPI version Last updated

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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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

philiprehberger_embedding_store-0.3.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file philiprehberger_embedding_store-0.3.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_embedding_store-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5dde7235f3b7926a2a2dfe550a7a45153b92eddf0744726912c5cf46f4b5138c
MD5 70447741ea126404f0a5c6f521cae047
BLAKE2b-256 9a745677ac31c974696c223d2dab9026e15062f370ab848349430dbecc351c42

See more details on using hashes here.

File details

Details for the file philiprehberger_embedding_store-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_embedding_store-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eda4622a9fe8984ab16cb98766062e7e394e61e9079a9218f0f52b31e70a16d4
MD5 4e46c43ba3ba016bdd7b27cf9ca2085e
BLAKE2b-256 3d076f5f960e136da7f457c6426e221c9088ba67f2e3907c6452b29b51cf71ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page