picovdb
An extremely fast, ultra-lightweight local vector database in Python.
"extremely fast": sub-millisecond query
"ultra-lighweight": One file with only Numpy and one optional dependency faiss-cpu. (See faiss note at the end)
Install
pip install picovdb
Usage
Create a db:
(Use SentenceTransformer embedding as example)
from picovdb import PicoVectorDB # On Mac, import before any libs that use pytorch
from sentence_transformers import SentenceTransformer
CHUNK_SIZE = 256
model = SentenceTransformer('all-MiniLM-L6-v2')
dim = model.get_sentence_embedding_dimension()
with open('A_Christmas_Carol.txt', encoding='UTF8') as f:
content = f.read()
num_chunks = len(content) // CHUNK_SIZE + 1
chunks = [content[i * CHUNK_SIZE: (i + 1) * CHUNK_SIZE] for i in range(num_chunks)]
embeddings = model.encode(chunks)
data = [
{
"_vector_": embeddings[i],
"_id_": i,
"content": chunks[i],
}
for i in range(num_chunks)
]
db = PicoVectorDB(embedding_dim=dim, storage_file='_acc')
db.upsert(data)
db.save()
Query
from picovdb import PicoVectorDB
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
dim = model.get_sentence_embedding_dimension()
db = PicoVectorDB(embedding_dim=dim, storage_file='_acc')
txt = "Are there no prisons? Are there no workhouses?"
emb = model.encode(txt)
q = db.query(emb, top_k=3)
print('query results:', q)
Benchmark
Embedding Dim: 1024.
Environment: M3 MacBook Air
-
Pure Python:
- Inserting
100,000vectors took about0.5s - Doing 100 queries from
100,000vectors took roughly0.8s (0.008s per quiry). - Doing 1000 queries from
100,000vectors in batch mode took1.0s (0.001s or1 millisecondper quiry).
- Inserting
-
With FAISS(cpu):
- Inserting
100,000vectors took110s - Doing 100 queries from
100,000vectors took0.04s (0.0004s or0.4 millisecondper quiry). - Doing 1000 queries from
100,000vectors in batch mode took0.1s (0.0001s or0.1 millisecondper quiry).
- Inserting
Environment: Windows PC with CPU Core i7-12700k and old-gen M2 Nvme SSD
-
Pure Python:
- Inserting
100,000vectors took about0.7s - Doing 100 queries from
100,000vectors took roughly1.5s (0.015s per quiry). - Doing 1000 queries from
100,000vectors in batch mode took1.0s (0.001s or1 millisecondper quiry).
- Inserting
-
With FAISS(cpu):
- Inserting
100,000vectors took50s - Doing 100 queries from
100,000vectors took0.04s (0.0004s or0.4 millisecondper quiry). - Doing 1000 queries from
100,000vectors in batch mode took0.16s (0.00016s or0.16 millisecondper quiry).
- Inserting
FAISS Note
On MacOS, if you use FAISS, please do one of following:
- import
picovdbbefore any libraries that usepytorch(e.g.sentence_transformers,transformers, etc) or any packages that use OpenMP. - set faiss_threads to 1 when initializing PicoVectorDB, e.g.
PicoVectorDB(..., faiss_threads=1). - set env var
PICOVDB_FAISS_THREADS=1before running your script.
Faiss >=1.10 will segfault on Darwin when using HNSW index with OpenMP multithreading. This is a known issue with FAISS on macOS.
On Windows and Linux, Faiss works fine with other libs that use OpenMP, no special care is needed.
Metadata
Release files for picovdb 0.2.1
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 | |
|---|---|---|---|---|
| picovdb-0.2.1.tar.gz | 14.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| picovdb-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.2 kB
Release files / picovdb-0.2.1.tar.gz
| Download URL | picovdb-0.2.1.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee67a0089fc12e97d90baeea7b1945940239c87f1345df418ebe526a3b12d320
|
|
BLAKE2b-256 checksum How to use checksums |
8f3e136b616b9ab12cabf2155b4655f710cad507531b459d73ae8cdbe6c98e12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.12.5 Linux/5.15.0-153-generic
|
Release files / picovdb-0.2.1-py3-none-any.whl
| Download URL | picovdb-0.2.1-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b172c614b3b2802422a5cafa4ce4f7940daa669dd951b5a938d58dec465366f
|
|
BLAKE2b-256 checksum How to use checksums |
80cd99f6ee6271ccff018c488aee71e1b0a406a2ec6e662ebfe8c3a1d55d8227
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.12.5 Linux/5.15.0-153-generic
|
Security for picovdb 0.2.1
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.