Skip to main content

chassisdb

Python bindings for Chassis, an embedded vector index for local semantic search: one file, in your process, no server.

Features

  • Zero-copy operations: Direct memory access via ctypes
  • NumPy integration: Native support for NumPy arrays
  • Type hints: Full type annotations for IDE support
  • Thread-safe: Search from many threads while another adds or deletes; writes run one at a time
  • Pythonic API: Context managers, properties, and familiar patterns

Installation

pip install chassisdb

The package is named chassisdb and imported as chassis. Wheels are built for Python 3.13 and later on Linux (x86-64 and ARM), macOS on Apple silicon and Windows (x86-64). Elsewhere, or from a checkout of the repository, pip install . in this directory builds it, which needs Rust.

Development Installation

# Build the library, then install with dev dependencies
cargo build --release -p chassis-ffi
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy chassis

# Formatting
black chassis tests
ruff check chassis tests

Quick Start

import numpy as np
from chassis import VectorIndex

# Create or open an index
index = VectorIndex("embeddings.chassis", dimensions=768)

# Add vectors
vectors = np.random.rand(1000, 768).astype(np.float32)
for i, vec in enumerate(vectors):
    vector_id = index.add(vec)
    print(f"Added vector {vector_id}")

# Flush to disk
index.flush()

# Search
query = np.random.rand(768).astype(np.float32)
results = index.search(query, k=10)

for result in results:
    print(f"ID: {result.id}, Distance: {result.distance:.6f}")

# Index info
print(f"Total vectors: {len(index)}")
print(f"Dimensions: {index.dimensions}")
print(f"Empty: {index.is_empty()}")

Advanced Usage

Custom HNSW Parameters

from chassis import VectorIndex, IndexOptions

# Configure HNSW parameters
options = IndexOptions(
    max_connections=32,      # Higher = better recall, more memory
    ef_construction=400,     # Higher = better index, slower build
    ef_search=100,           # Higher = better search, slower queries
    metric="cosine",         # "euclidean" (default) or "cosine"; fixed at creation
    precision="half",        # "full" (default) or "half": 16-bit floats, half the file; fixed at creation
)

index = VectorIndex("tuned.chassis", dimensions=768, options=options)

Context Manager

# Automatic resource cleanup
with VectorIndex("vectors.chassis", dimensions=128) as index:
    index.add([0.1] * 128)
    index.flush()
# Index is automatically closed here

Batch Operations

import numpy as np

vectors = np.random.rand(10000, 768).astype(np.float32)
queries = np.random.rand(100, 768).astype(np.float32)

with VectorIndex("large.chassis", dimensions=768) as index:
    # Added and linked on every core
    index.add_batch(vectors)
    index.flush()

    # One call for every query: ids and distances are (100, 10) arrays
    ids, distances = index.search_batch(queries, k=10)

NumPy Integration

import numpy as np

# From NumPy array
vec = np.array([0.1, 0.2, 0.3], dtype=np.float32)
index.add(vec)

# From list
index.add([0.1, 0.2, 0.3])

# From tuple
index.add((0.1, 0.2, 0.3))

# All are automatically converted to float32

Error Handling

from chassis import VectorIndex, DimensionMismatchError, IndexLockedError

index = VectorIndex("vectors.chassis", dimensions=128)
try:
    index.add([0.1] * 64)
except DimensionMismatchError as e:
    print(e)
    # The vector has 64 components, but this index holds vectors of 128
    # help: make the vector with the same model as the index's vectors; this index was created for 128 dimensions

try:
    VectorIndex("vectors.chassis", dimensions=128)
except IndexLockedError:
    # One writer at a time; a reader searches while it writes.
    reader = VectorIndex("vectors.chassis", dimensions=128, read_only=True)

API Reference

VectorIndex

Main class for interacting with Chassis indexes.

Constructor

VectorIndex(path: str | Path, dimensions: int, options: IndexOptions | None = None)

Methods

  • add(vector: Sequence[float] | ndarray) -> int
    Add a vector to the index. Returns the vector ID.

  • add_batch(vectors: ndarray, ids: Iterable[int] | None = None) -> ndarray
    Add a (count, dimensions) array at once, linking it on every core: much faster than add in a loop. Returns the ids. All or nothing: if any vector or id is rejected, none is added.

  • search(query: Sequence[float] | ndarray, k: int = 10, allowed: Iterable[int] | ndarray | None = None) -> List[SearchResult]
    Search for k nearest neighbors. Returns sorted list of results. With allowed, only those ids can be returned, e.g. allowed=[row[0] for row in db.execute("SELECT id FROM docs WHERE owner = ?", (user,))]; when walking the graph would cost more, as when few vectors match, every vector is checked instead and the results are exact.

  • search_batch(queries: ndarray, k: int = 10) -> tuple[ndarray, ndarray]
    Search for the k nearest neighbors of each row of a (count, dimensions) array, in one call: faster than search in a loop. Returns (ids, distances), two (count, k) arrays, nearest first; a row with fewer than k results is filled out with id 2**64 - 1 and distance inf.

  • flush() -> None
    Flush changes to disk. Call after batch insertions.

  • warm() -> None
    Read the index into memory on another thread, so that searches stop waiting for the disk while its file is not in memory yet, as after a reboot. Returns at once; searches go on meanwhile. IndexOptions(warm=True) does the same from the moment the index is opened.

  • compact() -> None
    Rewrite the index without its deleted vectors and with a rebuilt graph, reclaiming their space. Ids don't change. Takes as long as building the index and needs disk for a second copy.

  • close() -> None
    Close the index and free resources. Called automatically.

  • __len__() -> int
    Get number of vectors in the index.

  • is_empty() -> bool
    Check if index is empty.

Properties

  • dimensions: int - Number of dimensions per vector
  • metric: str - "euclidean" or "cosine", as the index was created; opening with read_only=True and explicit options naming another raises ChassisError
  • precision: str - "full" or "half", as the index was created
  • path: Path - Path to the index file
  • options: IndexOptions - HNSW configuration

IndexOptions

Configuration for HNSW algorithm.

@dataclass
class IndexOptions:
    max_connections: int = 16      # M parameter
    ef_construction: int = 200     # Build-time search quality
    ef_search: int = 50            # Query-time search quality
    metric: str = "euclidean"      # or "cosine": 1 - cosine similarity, unit-length storage
    precision: str = "full"        # or "half": vectors kept as 16-bit floats, half the file and memory
    huge_pages: bool = False       # Linux: keep the vectors on 2 MB pages (faster search on a large index)
    warm: bool = False             # read the index into memory in the background from the start

SearchResult

Search result with ID and distance.

@dataclass
class SearchResult:
    id: int          # Vector ID in index
    distance: float  # Distance to query (lower = closer)

Exceptions

Each says what was wrong, with the value, and on a line starting help: what to do instead. Each is a ChassisError and also the built-in exception it is a kind of, so except ValueError catches a bad argument. The errors reference lists their causes and fixes.

  • InvalidArgumentError (ValueError) - an argument out of range: dimensions, an option, an id, a vector with NaN or infinity. A wrong type is a plain TypeError.
  • DimensionMismatchError (ValueError) - a vector or query of other dimensions than the index's
  • OptionsMismatchError (ValueError) - reopened with another metric or precision
  • IndexNotFoundError (FileNotFoundError) - no index at the path, for read_only=True
  • NotAnIndexError (ValueError) - the file isn't a Chassis index
  • IdInUseError (ValueError) - the id is taken; delete it first to replace it
  • IndexLockedError - another writer has the index open
  • ReadOnlyError - a read_only=True index asked to write
  • CorruptIndexError, IndexFullError, InvalidPathError (OSError) - a damaged file, a full index, an operating-system error

Thread Safety

Every method is safe to call from any thread. Searches run concurrently (ctypes releases the GIL during each call); add(), delete() and flush() take the index's write lock, so they run one at a time and searches wait for them. Don't call close() while other threads still use the index.

Other processes can search the file while one process writes it: open it with VectorIndex(path, dimensions, read_only=True). Such an index takes no lock, sees the writer's newest flush() on every search, runs one search at a time, and raises ChassisError on writes. A flush becomes visible just before its final fsync, so one that then fails, or is lost to power loss, may already have been seen.

from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor() as pool:
    results = list(pool.map(lambda q: index.search(q, k=10), queries))

Performance Tips

  1. Batch inserts before flushing:

    for vec in many_vectors:
        index.add(vec)
    index.flush()  # Once at the end
    
  2. Use NumPy arrays:

    # Faster (zero-copy)
    vec = np.array([0.1] * 768, dtype=np.float32)
    
    # Slower (creates copy)
    vec = [0.1] * 768
    
  3. Tune HNSW parameters:

    • Increase ef_construction for better index quality
    • Increase ef_search for better search recall
    • Increase max_connections for better graph connectivity
  4. Use context managers:

    with VectorIndex(...) as index:
        # Automatic cleanup
    

Library Location

chassisdb looks for libchassis_ffi in this order:

  1. CHASSIS_LIB_PATH environment variable
  2. Next to the Python package
  3. ../target/release (development)
  4. System library paths

To set a custom location:

export CHASSIS_LIB_PATH=/path/to/lib
python your_script.py

Examples

See the examples/ directory for complete examples:

  • basic_usage.py - Simple add and search
  • batch_insert.py - Efficient bulk loading

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=chassis --cov-report=html

# Run specific test
pytest tests/test_index.py::test_add_and_search

License

Licensed under either of:

at your option.

Contributing

See CONTRIBUTING.md for development guidelines.

Metadata

Release files for chassisdb 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for chassisdb 0.7.2
File
chassisdb-0.7.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
chassisdb-0.7.2-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
chassisdb-0.7.2-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details
chassisdb-0.7.2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 1.6 MB

Release files / chassisdb-0.7.2-py3-none-win_amd64.whl

Download URL chassisdb-0.7.2-py3-none-win_amd64.whl
Size 326.8 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
86c94cb52e7303caabe250519f197a3157eefb9879d196198ea29ab596c7df7f
BLAKE2b-256 checksum
How to use checksums
cf1b51ea294ac4e92228a0a5bb8d5ebdbf4b4391c97adbcbcd4a7c9c72a79cc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release files / chassisdb-0.7.2-py3-none-manylinux_2_28_x86_64.whl

Download URL chassisdb-0.7.2-py3-none-manylinux_2_28_x86_64.whl
Size 476.3 kB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
478b6ad457acae2e96401dc24129758c89d3add91e5c55da9cc9682ebe101599
BLAKE2b-256 checksum
How to use checksums
cc3edbeb5f2e6d5ac6d110c4373aef44b5163c5982b37bca70286c6bedb3bbc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release files / chassisdb-0.7.2-py3-none-manylinux_2_28_aarch64.whl

Download URL chassisdb-0.7.2-py3-none-manylinux_2_28_aarch64.whl
Size 436.8 kB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
159eb33b82d343fde40abadd16c4c16966ab683bf42e82141df834fffc847d21
BLAKE2b-256 checksum
How to use checksums
1542ad1173b87423ce0ccb83830df5c2aa39c8166c758841f7ab465cf3570b14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release files / chassisdb-0.7.2-py3-none-macosx_11_0_arm64.whl

Download URL chassisdb-0.7.2-py3-none-macosx_11_0_arm64.whl
Size 392.5 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e60063edbe7d735eea01ec0c86d31600e598980e0f6afb38ec0389b7583d85f0
BLAKE2b-256 checksum
How to use checksums
399673d035e2b1fab7c014b0fd8543bb4933e12a91a957678b5d367d48432698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

4 release files

This release

0.7.2 This release

4 release files

0.7.1

4 release files

0.7.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page