Skip to main content

Embedded two-stage cascading vector index (1-bit graph routing + 3-bit TurboQuant + exact rerank)

Project description

quantal (Python)

Embedded, in-memory vector index — 1-bit graph routing + 3-bit TurboQuant payloads + exact rerank — with a ctypes binding to the Zig core.

Install

pip install -e python      # from a source checkout (builds libs on demand)

quantal fixes the vector dimension at compile time, so there is one native library per dimension. The binding resolves it automatically, in order:

  1. QUANTAL_LIB — an explicit library path (overrides everything).
  2. Bundled binary — the published wheels carry prebuilt libraries for the common embedding dimensions (256, 384, 512, 768, 1024, 1536, 3072), so pip install quantal works with no toolchain for those dims.
  3. Cached build under ~/.cache/quantal/.
  4. Build on demand — from a source checkout with zig on PATH, Index(dim=N) builds and caches the library for any other dimension.

So a stock embedding model "just works" from a wheel; an unusual dimension needs either a source checkout (auto-build) or a manual zig build -Dc-dim=N + QUANTAL_LIB.

Building wheels

cd python
python build_libs.py                 # compile bundled dims into quantal/_libs/
python -m build --wheel              # -> dist/quantal-...-py3-none-<platform>.whl

build_libs.py --target x86_64-linux-gnu.2.28 pins glibc so the Linux wheel is manylinux-compatible (Zig cross-compiles directly — no Docker). CI in .github/workflows/wheels.yml builds Linux/macOS/Windows wheels this way.

Core API

import numpy as np
from quantal import Index

with Index(dim=384) as index:
    ids = index.add(vectors)               # (n, 384) float32 -> auto ids
    hits = index.search(query, k=10)        # -> [(id, score), ...] cosine
    scores, ids, counts = index.search_batch(queries, k=10, threads=0)
    index.remove(ids[0])
    index.save("docs.tq")

index = Index.load("docs.tq")               # dimension read from the file

search_filtered(query, allowlist, k) restricts results to a set of ids (exact scoring over the allowlist — for tenant/ACL filtering).

LangChain

A one-line swap for the in-memory / FAISS store:

from quantal.langchain import QuantalVectorStore

vs = QuantalVectorStore.from_texts(texts, embedding=my_embeddings,
                                      metadatas=metas)
docs = vs.similarity_search("query", k=5)
retriever = vs.as_retriever(search_kwargs={"k": 5})

vs.save("store.qj")                         # store.qj.tq + store.qj.json
vs = QuantalVectorStore.load("store.qj", embedding=my_embeddings)

Vectors are L2-normalized in and out, so scores are cosine similarity. The engine stores vectors keyed by id; documents and metadata live in a JSON sidecar persisted next to the .tq.

LlamaIndex

from quantal.llama_index import QuantalVectorStore
from llama_index.core import VectorStoreIndex, StorageContext

store = QuantalVectorStore()                      # dim inferred from nodes
ctx = StorageContext.from_defaults(vector_store=store)
index = VectorStoreIndex(nodes, storage_context=ctx, embed_model=embed)
hits = index.as_retriever(similarity_top_k=5).retrieve("query")

LangGraph (agent memory)

A BaseStore with semantic search — local, fast short/long-term memory for agent graphs. Per-namespace search is served by quantal's exact allowlist scoring, so namespaces are isolated precisely.

from quantal.langgraph_store import QuantalStore

store = QuantalStore(index={"dims": 384, "embed": embed_fn, "fields": ["text"]})
store.put(("memories", "alice"), "m1", {"text": "prefers dark mode"})
hits = store.search(("memories", "alice"), query="ui preferences", limit=5)

Without an index config it is a plain namespaced key-value store.

Tests

QUANTAL_LIB=... python python/tests/test_index.py
python python/tests/test_langchain.py      # needs langchain-core

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

quantaldb-0.1.0-py3-none-win_amd64.whl (2.2 MB view details)

Uploaded Python 3Windows x86-64

quantaldb-0.1.0-py3-none-manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

quantaldb-0.1.0-py3-none-manylinux_2_28_aarch64.whl (8.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

quantaldb-0.1.0-py3-none-macosx_14_0_arm64.whl (1.4 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file quantaldb-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: quantaldb-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quantaldb-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 03d7c2876649afae7fc32318fa9cb3b668f8032d2706342f287e48067045a54f
MD5 20bdf83c20eb2ae1e67f2f435491f4b0
BLAKE2b-256 6baf31c95249b6a073e62cc983ec6aa3c03ec99b3f2efef13fce1c65873665de

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantaldb-0.1.0-py3-none-win_amd64.whl:

Publisher: wheels.yml on PaytonWebber/quantal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quantaldb-0.1.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for quantaldb-0.1.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 11eefe6675e7c24508256c7e30fc1a20666b94434d98b1d5d0adcc383d6e6458
MD5 56dfb0103c1edf92e872062e9ca2c978
BLAKE2b-256 aaa25af796d5d943b257258a0e7557bbbe2b0d1debd462d19e9688a50d8d310a

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantaldb-0.1.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on PaytonWebber/quantal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quantaldb-0.1.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for quantaldb-0.1.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e4fc75f742655f48b407564fd5e5335385226df752f5812d9b06d4da2a825179
MD5 26c9e3a1e61fdfb1cfea1b7ca0840f46
BLAKE2b-256 d27bab12a2969a187b7127c0a39acd5fe3847757f293213afd984ca36b53c3ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantaldb-0.1.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on PaytonWebber/quantal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quantaldb-0.1.0-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for quantaldb-0.1.0-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 403a4c0b270a8037687e466c9176ee4579f2634e3336c458665696ee8a248cd5
MD5 39fee438f4b4e5bec5f22c7e19b91a1a
BLAKE2b-256 454febd89be69ab21f733c379bf9cc704b795d526fdfc1dd6fbbaac43a39188a

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantaldb-0.1.0-py3-none-macosx_14_0_arm64.whl:

Publisher: wheels.yml on PaytonWebber/quantal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page