vd.backends.memory#
In-memory backend — the reference adapter.
Stores documents in a plain dict and answers queries with brute-force
similarity in pure Python. Always available (no third-party dependency), and
the canonical example of how a backend implements the small set of raw
primitives that AbstractCollection builds on. Use it for
tests, notebooks, and corpora small enough that an ANN index is overkill.
Classes
|
In-memory vector database client. |
|
A collection backed by an in-process |
- class vd.backends.memory.MemoryClient(*, embedder=None, **config)[source]#
Bases:
AbstractClientIn-memory vector database client.
Examples
>>> import vd >>> client = vd.connect('memory') >>> col = client.create_collection('docs') >>> col['a'] = vd.Document(id='a', text='cat', vector=[1.0, 0.0]) >>> col['b'] = vd.Document(id='b', text='dog', vector=[0.0, 1.0]) >>> [r['id'] for r in col.search([0.9, 0.1], limit=1)] ['a']
- create_collection(name, *, dimension=None, metric='cosine', **index_config)[source]#
Create a new collection.
- Parameters:
name (
str) – Collection name.dimension (
Optional[int]) – Vector dimension. May beNonefor backends that can infer it from the first written vector; required up front by backends that cannot.metric (
str) – Distance metric:"cosine","dot", or"l2".**index_config – Backend-specific index tuning (HNSW
M/ef, IVFnlist, …). Documented per adapter; never abstracted into a common enum.
- Raises:
ValueError – If a collection of that name already exists.
- Return type: