pyvecdb
An educational vector database library built from scratch in Python. Part of the PyLearn platform for kids aged 12+.
What is a Vector Database?
A vector database stores vectors (lists of numbers) and finds similar ones. Think of it like a music app that turns songs into lists of numbers and finds other songs with similar numbers!
Features
- Vector Operations -- add, subtract, scale, normalize, dot product, magnitude
- Vector Store -- CRUD operations for vector records with dimensionality checks
- Distance Metrics -- cosine similarity, Euclidean, Manhattan, dot product
- KNN Search -- find the K most similar vectors to a query
- Metadata Filtering -- filter results by metadata (eq, ne, gt, gte, lt, lte, in)
- Batch Operations -- insert and search multiple vectors at once
- Persistence -- save/load to JSON files
- Pure Python -- no external dependencies
Quick Start
from pyvecdb import VectorStore, knn_search
# Create a store for 3-dimensional vectors
store = VectorStore(dimensions=3)
# Insert some songs as vectors (energy, happiness, danceability)
store.insert("thunder", [0.9, 0.6, 0.7], metadata={"genre": "rock", "year": 2017})
store.insert("lullaby", [0.1, 0.8, 0.2], metadata={"genre": "folk", "year": 2020})
store.insert("party-rock", [0.95, 0.9, 0.99], metadata={"genre": "pop", "year": 2011})
store.insert("ballad", [0.3, 0.4, 0.1], metadata={"genre": "rock", "year": 2019})
# Find the 2 most similar songs to a high-energy query
results = knn_search(store, query=[0.85, 0.7, 0.8], k=2)
for record, score in results:
print(f"{record.record_id}: {score:.3f}")
# party-rock: 0.998
# thunder: 0.995
# Filter by metadata -- only rock songs
results = knn_search(
store,
query=[0.85, 0.7, 0.8],
k=2,
metadata_filter={"genre": "rock"},
)
Installation
git clone https://github.com/robcox2910/pyvecdb.git
cd pyvecdb
uv sync --all-extras
Development
uv run ruff check src/ tests/ # Lint
uv run ruff format src/ tests/ # Format
uv run pyright src tests # Type check
uv run pytest # Test (90%+ coverage)
Releasing
Other projects in the series (PyStack) use a pinned release of this one,
not whatever is on main. To publish a change for them:
- Merge the change to
main. - Tag it:
git tag -a vX.Y.Z -m vX.Y.Z && git push origin vX.Y.Z. A change to the public API bumps the minor version (v0.1.0→v0.2.0); anything else bumps the patch (v0.1.0→v0.1.1). - In each project that uses it, edit the tag in
[tool.uv.sources], runuv lock --upgrade-package <name>, and open a pull request so CI checks the pair together.
Related Projects
This project is one of a series that builds real systems "from scratch in Python" to teach how they work. See the series home for the full story.
| Project | What it teaches | Repository | Docs |
|---|---|---|---|
| PyOS | Operating systems | py-os | Docs |
| Pebble | Compilers and programming languages | pebble-lang | Docs |
| PyDB | Relational databases | pydb | Docs |
| PyKV | Key-value stores | pykv | Docs |
| PyDocDB | Document databases | pydoc-db | Docs |
| PyGraphDB | Graph databases | pygraphdb | Docs |
| PyTSDB | Time-series databases | pytsdb | Docs |
| PyVecDB | Vector databases | pyvecdb | Docs |
| PyColDB | Column-family databases | pycoldb | Docs |
| PyCrypt | Cryptography | pycrypt | Docs |
| PyNet | Computer networking | pynet | Docs |
| PyWeb | HTTP web servers | pyweb | Docs |
| PyGit | Version control | pygit | Docs |
| PySearch | Search engines | pysearch | Docs |
| PyMQ | Message queues | pymq | Docs |
| PyLLM | Language models (the brain) | pyllm | Docs |
| PyScheduler | Job scheduling | pyscheduler | Docs |
| PyStack | Full-stack integration | pystack | Docs |
Documentation
Full docs (with kid-friendly explanations of every idea): https://robcox2910.github.io/pyvecdb/
License
MIT
Metadata
Release files for fromscratch-pyvecdb 0.3.0
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 | |
|---|---|---|---|---|
| fromscratch_pyvecdb-0.3.0.tar.gz | 90.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fromscratch_pyvecdb-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 111.2 kB
Release files / fromscratch_pyvecdb-0.3.0.tar.gz
| Download URL | fromscratch_pyvecdb-0.3.0.tar.gz |
|---|---|
| Size | 90.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bcf7e086dac694e74fd7313f8cd14fa2d94525da430c3a6f7b87891740d6eb2
|
|
BLAKE2b-256 checksum How to use checksums |
3b5a3670baeebf00e2a4bd10e67201e071d4569d958815798c2cece58e546851
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / fromscratch_pyvecdb-0.3.0-py3-none-any.whl
| Download URL | fromscratch_pyvecdb-0.3.0-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a05249df714b644df04d9729d780299632f7c0729863994b7def8a6e026cf2a
|
|
BLAKE2b-256 checksum How to use checksums |
4aed8f91d6901c0107a56ad214b408affa379c703b1d38d12d1b64607d9c1e27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for fromscratch-pyvecdb 0.3.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fromscratch_pyvecdb-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA 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.