Skip to main content

Algorithmic code embeddings — TF-IDF + pretrained nomic-embed-code vectors. No GPU, no API keys, no model download.

Project description

fast-code-embed (Python)

Pythonic interface to the fast-code-embed C library: algorithmic code embeddings using TF-IDF + pretrained nomic-embed-code token vectors (with optional Reflective Random Indexing).

  • No GPU, no API keys, no model download — the 30 MB vector table is compiled into the wheel.
  • Sub-millisecond scoring — lookup-based, no transformer inference.

Status: sketch / not yet published. This package mirrors the Java binding's surface. The wheel links the prebuilt C static library, so make lib must run before building (cibuildwheel handles this in CI).

Install (once published)

pip install fast-code-embed

Usage

import fast_code_embed as fce

# Global config (maps to the C library's process-state toggles; set once).
fce.set_dim(768)              # 256 or 768
fce.set_idf_weighting(True)
fce.set_abbrev_expansion(False)

with fce.Corpus() as corpus:
    corpus.add_doc("parse_config", "def parse_config(path): ...")
    corpus.add_doc("retry_request", "def retry_request(url, attempts): ...")
    # or: corpus.add_files(["a.py", "b.py"])  # chunk + tokenize in C
    corpus.finalize()

    for hit in corpus.search("load configuration from disk", k=10):
        print(f"{hit.score:.3f}  {hit.label}")

    # Persist while the corpus is still open (same-build cache, not portable
    # across dim / byte-order).
    corpus.save("index.fce")

# Reload later into a fresh corpus.
with fce.Corpus.load("index.fce") as reloaded:
    hits = reloaded.search("retry with backoff", k=5)

Search modes

from fast_code_embed import Mode
corpus.search("retry with backoff", k=5, mode=Mode.BRUTEFORCE)  # exhaustive
corpus.search("retry with backoff", k=5, mode=Mode.FAST)        # inverted index
corpus.search("retry with backoff", k=5, mode=Mode.TFIDF)       # tf-idf + rerank
# Mode.DEFAULT == AUTO (fast path, brute fallback)

Mode.FAST/TFIDF/AUTO only retrieve documents sharing a literal token with the query; use Mode.BRUTEFORCE when exhaustive recall matters.

Building locally

cd ..             # repo root
make lib          # produces build/libfast_code_embed.a (with embedded blob)
cd python
pip install -e .  # compiles the cffi extension against the archive

Building wheels

pip install cibuildwheel
cibuildwheel --output-dir wheelhouse python

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.

fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_x86_64.whl (19.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_aarch64.whl (19.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ ARM64

fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_x86_64.whl (19.3 MB view details)

Uploaded CPython 3.9+macOS 11.0+ x86-64

fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (19.5 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f6c22b8b0264a89c3d1b3533565a3dc056b045cca16b008512cc4a33b0faa623
MD5 ec00296e8ece4293d2c9cf5cc695f8fd
BLAKE2b-256 adf7d06e0ed50cc140fae6a664b6da9e8b56151f428472bf8297512a2a6cd05b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_x86_64.whl:

Publisher: python-release.yml on nilsonsfj/fast-code-embed

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

File details

Details for the file fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4d9ee3d386d4ae5c53fded75735e689b5b5f356c0dfe75ef73f28a47d5505f9f
MD5 0ddfea434ec83080dcbb544ff141baca
BLAKE2b-256 f9466312f3e0810506d5bbab70b10769060d29c1477131264c3c9b02dae838bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_code_embed-0.1.2-cp39-abi3-manylinux_2_34_aarch64.whl:

Publisher: python-release.yml on nilsonsfj/fast-code-embed

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

File details

Details for the file fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f69cc578dc1904269a0e0a77c50083c83b1331d536aa3794dd72c2af27e78149
MD5 73d112b6b63af41ecf6409b267e3d087
BLAKE2b-256 b3cda17ad685c836ca387fc3724d3a61c6dc807e462bceb05558390dc6c7da3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_x86_64.whl:

Publisher: python-release.yml on nilsonsfj/fast-code-embed

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

File details

Details for the file fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b719b516a994f265f2a4eb0ffb07ece7660a57a0d962f6925f024001be3e6be4
MD5 596d0c689598cf27c6d86b84a167bcb3
BLAKE2b-256 3ba9fe868130e20cdfdec1363831fd86ea72bce4b4d47f637154bce934025ec0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_code_embed-0.1.2-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: python-release.yml on nilsonsfj/fast-code-embed

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