muninn-db
muninn is an embedded vector database and full-text search engine: it runs inside your Python program, stores its data in a directory, and searches by vector similarity, by keywords (BM25), or both at once (hybrid search), with filters on your own fields. Writes are durable: every acknowledged write survives a crash.
pip install muninn-vectordb
From the 1.0.0 release on, wheels are published for Linux (x86-64 and ARM64) and Windows (x86-64), for Python 3.9 and later. numpy (1.19 or later) is the only dependency.
Quick start
import numpy as np
import muninn_db
with muninn_db.Database.open("data") as db:
docs = db.create_collection("docs", {
"vector": {"dim": 3, "metric": "cosine"},
"text_fields": ["title"],
"filterable": {"lang": "keyword", "year": "integer"},
})
docs.upsert([
{"id": 1, "vector": [0.1, 0.2, 0.3],
"text": {"title": "an embedded database"},
"payload": {"lang": "en", "year": 2024}},
{"id": "b2", "vector": [0.3, 0.1, 0.0],
"text": {"title": "eine eingebettete Datenbank"},
"payload": {"lang": "de", "year": 2021}},
])
# Vector search.
hits = docs.search([0.1, 0.2, 0.25], k=5)
# Keyword search.
hits = docs.search(text="database")
# Hybrid search with a filter, returning the payloads.
hits = docs.search(
np.array([0.1, 0.2, 0.25], dtype=np.float32), text="database",
filter={"and": [{"eq": {"lang": "en"}}, {"range": {"year": {"gte": 2020}}}]},
with_payload=True)
for h in hits:
print(h.id, h.score, h.vector_score, h.text_score, h.payload)
Opening a database
Database.open(path, options=None, **options) opens the directory, creating it if needed, and recovers every acknowledged write. One process at a time may open a directory; a second attempt raises DatabaseLockedError.
db = muninn_db.Database.open("data", durability="batch", sync_interval_ms=10)
...
db.close() # or use `with`
| option | meaning | default |
|---|---|---|
durability |
"each": on disk before a write returns. "batch": on disk within sync_interval_ms (a power cut can lose that much). "none": left to the operating system (survives the program crashing, not the machine). |
"each" |
sync_interval_ms |
longest delay with "batch" |
10 |
memtable_max_docs |
documents kept in memory per collection before they are written to disk | 50 000 |
auto_compact |
merge on-disk parts in the background | True |
muninn_db.Options lists every setting with its documentation; pass it as the second argument or use the same names as keywords.
close() waits for running operations, then stops background work and unlocks the directory; afterwards every call on the database and its collections raises DatabaseClosedError. Nothing is lost by not calling flush() first.
Collections and schemas
A schema is fixed when the collection is created. Write it as a dict (the same form as the HTTP API) or with the schema classes:
from muninn_db import Schema, VectorField, Hnsw
schema = Schema(
vector=VectorField(384, metric="cosine", index=Hnsw(m=16, ef_construction=200),
quantization="none"),
text_fields=["title", "body"],
analyzer="english",
filterable={"lang": "keyword", "year": "integer", "price": "float",
"meta.public": "bool"},
)
docs = db.create_collection("docs", schema)
| setting | values | default |
|---|---|---|
vector.dim |
1 to 65536 (required) | |
vector.metric |
"cosine", "dot", "l2" |
"cosine" |
vector.index |
Hnsw(m, ef_construction) / "hnsw" (approximate, fast at any size), Flat() / "flat" (exact) |
HNSW, m 16, ef_construction 200 |
vector.quantization |
"none", "sq8" (one byte per dimension), "binary" (one bit); the best candidates are re-checked exactly |
"none" |
text_fields |
names of the full-text fields | none |
analyzer |
"default" (lowercase only), "english" (accent folding, stop words, stemming), or Analyzer(...) |
"default" |
filterable |
payload fields usable in filters: {name: "keyword" | "integer" | "float" | "bool"}; dotted names reach nested objects |
none |
A schema needs a vector field, at least one text field, or both. Other collection calls:
db.collection("docs") # an existing collection
db.get_or_create_collection("docs", schema) # either
db.list_collections() # ["docs", ...]
"docs" in db # True
db.drop_collection("docs") # deletes it and its files
docs.schema # a muninn_db.Schema
Writing documents
A document has an id (a non-negative integer below 2**64, or a string; 7 and "7" are different documents), a vector when the collection has a vector field, text for any of the declared text fields, and an optional payload: any JSON-like value (dicts, lists, strings, numbers, booleans, None). Writing an existing id replaces the document.
docs.upsert([{"id": 1, "vector": vec, "text": {"title": "..."}, "payload": {...}}])
For bulk loads, pass columns instead. A float32 numpy array is read directly from its memory; other arrays and lists are converted first.
n = 100_000
docs.upsert(
ids=np.arange(n), # or a list of ints / strs
vectors=np.random.rand(n, 384).astype(np.float32), # shape (n, dim)
texts={"title": titles}, # {field: [str, ...]}
payloads=[{"lang": "en"}] * n, # one per id, or None
batch_size=10_000,
)
Every upsert call is all-or-nothing: if any document is invalid nothing is stored, and after a crash either the whole call is there or none of it. With batch_size, each batch of that many documents is all-or-nothing instead (one batch may hold up to about 1 GB). When the call returns, the documents are searchable and as durable as the durability option promises.
docs.delete([1, "b2"]) # returns how many of the ids existed
docs.get(1) # {"id": 1, "vector": array([...], dtype=float32),
# "text": {...}, "payload": {...}} or None
len(docs) # documents that can be found
Searching
hits = docs.search(vector=None, text=None, *, k=10, filter=None, ids=None,
fusion=None, fields=None, with_payload=False, ef=None,
rerank=None, candidates=None)
A vector alone is a nearest-neighbour search, text alone a keyword search (a document matches if it contains any of the words), both a hybrid search.
| argument | meaning | default |
|---|---|---|
k |
number of results | 10 |
filter |
payload filter (below) | none |
ids |
only these document ids | all |
fusion |
hybrid only: Rrf(k=60) / {"rrf": {"k": 60}} (reciprocal-rank fusion) or Weighted(vector=0.7, text=0.3) / {"weighted": {...}} |
Rrf(60) |
fields |
text fields to search; a document scores its best field | all |
with_payload |
include each hit's payload | False |
ef |
HNSW candidate-list size; larger is more accurate and slower | 64 |
rerank |
quantised candidates re-checked exactly | 4k (sq8), 16k (binary) |
candidates |
hybrid only: candidates per side before fusion | max(4k, 40) |
Each Hit has id, score (higher is better: the cosine similarity, dot product or minus the squared Euclidean distance for vector searches, BM25 for keyword searches, the fused score for hybrid ones), vector_score and text_score (each side's score, or None if that side did not find the document) and payload (with with_payload=True). hit.to_dict() gives a dict. Equal scores come back in the order the documents were written.
Many vector queries at once run in parallel on all CPU cores:
results = docs.search_batch(queries, k=10) # queries: shape (n, dim)
Filters
Filters are dicts in the same language as the HTTP API. Fields must be declared filterable in the schema.
{"eq": {FIELD: VALUE}}
{"in": {FIELD: [VALUE, ...]}}
{"range": {FIELD: {"gt" | "gte" | "lt" | "lte": NUMBER, ...}}}
{"exists": FIELD}
{"and": [filter, ...]}
{"or": [filter, ...]}
{"not": filter}
A field holding a list matches when any element matches. A payload value of the wrong kind (text where a number is declared) counts as missing. Filters are applied during the search, so k hits come back whenever k documents match.
Maintenance
docs.flush() # write in-memory documents to disk, shorten the log
docs.compact() # merge all on-disk parts, dropping deleted documents
docs.stats() # {"live_docs": ..., "deleted_docs": ..., "segments": [...], ...}
db.stats() # {name: stats} for every collection
Neither is needed for durability or for searches to see new documents; both happen automatically in the background.
Threads and processes
A Database and its collections may be used from many threads at once. Searches and writes run without holding the GIL, so searches from several threads run in parallel, and concurrent writers share disk flushes. Ctrl-C (KeyboardInterrupt) arrives when the running call returns; a call is never cut off halfway.
Only one process at a time may open a database directory. A child process created with fork (the default start method of multiprocessing on Linux before Python 3.14) gets a copy of the parent's Database objects but not the background threads behind them, so it cannot use them: every call raises ForkedProcessError, and close() there only marks the copy closed, leaving the parent's database untouched. Open the database in the process that uses it, and start child processes with the "spawn" or "forkserver" method if they need to open it themselves (after the parent closed it).
A collection keeps its database open: as long as a Collection is in use, the directory stays locked even if the Database object is gone. collection.database returns the database, for example to close it.
Errors
Every error is a muninn_db.MuninnError; most also derive from the built-in exception that fits:
| exception | also | when |
|---|---|---|
InvalidArgumentError |
ValueError |
a wrong vector dimension, an invalid schema or filter, an undeclared text or filter field, a negative id |
NotFoundError |
LookupError |
an unknown collection |
AlreadyExistsError |
creating a collection whose name is taken | |
CorruptionError |
damaged files | |
UnsupportedError |
data written by a newer version of muninn; nothing is changed on disk, open it with that version again | |
UnavailableError |
a collection that stopped accepting writes after a disk failure; reopening the database recovers it | |
DatabaseClosedError |
ValueError |
using a closed database |
ForkedProcessError |
RuntimeError |
using a database in a child process created with fork (see above) |
StorageError |
OSError |
disk errors |
DatabaseLockedError |
StorageError |
the directory is open elsewhere |
Wrong Python types raise TypeError (a float where an integer is expected, bytes where ids or vectors are expected); numbers out of range (k=0, a negative option) raise InvalidArgumentError.
License
MIT. Source, the HTTP server and the Rust library: https://github.com/KRuskowski/muninn.
Metadata
Release files for muninn-vectordb 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| muninn_vectordb-1.0.2.tar.gz | 546.2 kB | Without provenance | Details for muninn_vectordb-1.0.2.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| muninn_vectordb-1.0.2-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for muninn_vectordb-1.0.2-cp39-abi3-win_amd64.whl |
| muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ x86-64 | Details for muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_x86_64.whl |
| muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details for muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_aarch64.whl |
Total release size: 4.0 MB
Release files / muninn_vectordb-1.0.2.tar.gz
| Download URL | muninn_vectordb-1.0.2.tar.gz |
|---|---|
| Size | 546.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b5fee18c6d0ab077e57524b074acfe345b75026e919bf6e336baab259fbc192
|
|
BLAKE2b-256 checksum How to use checksums |
914185d396ac15062b177acb516bcefadb181ed75aa38d7141118bb54d798f23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / muninn_vectordb-1.0.2-cp39-abi3-win_amd64.whl
| Download URL | muninn_vectordb-1.0.2-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
583bae01a06b9fdc4bc197a671401ff8c77138921caa121fdff120d3d12ad656
|
|
BLAKE2b-256 checksum How to use checksums |
738380b947ba92ea390e9c01adea0419a1040fe515cf69202ac7aac45826ef47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6462fe6c236987787c324ee4c53a74145882bf65c592588a7db9c44f14775702
|
|
BLAKE2b-256 checksum How to use checksums |
a72e7c9b73ba592c49c142a5dba17f78f5b3b3ee6892b496532087a939fcb8a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | muninn_vectordb-1.0.2-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0d05f491ce16281c2eb209d541df8801fbd1f19555f1403e57f028fc5b470076
|
|
BLAKE2b-256 checksum How to use checksums |
b425b02e6d2f7d4f95e626f7d3d9a3d89d5c23d27621978998388d0291a4a814
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for muninn-vectordb 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.