Skip to main content

Local in-memory hybrid analytical index for Python

Project description

Balarama

Balarama is a local in-memory hybrid analytical index for Python.

The core idea is simple:

  • keep rows as the source of truth
  • build sorted per-column access paths
  • load data once
  • run many repeated local queries and analytics very quickly

The primary use case now is a code corpus slice explorer for AI-assisted software development. You load function metadata once, then repeatedly filter by language, repo, split, code_len_chars, doc_len_chars, code_line_count, and similar fields for corpus prep, eval slicing, and prompt/example selection.

What Works Today

The implemented path is centered on the original hybrid design:

  • native C table engine with one row store and one sorted index array per column
  • bulk-friendly load-once path that appends rows first and builds indexes once
  • Python HybridTable API for equality/range filtering, counts, sums, row reconstruction, and value counts
  • higher-level CodeCorpusExplorer API for the CodeSearchNet metadata workflow
  • sample code corpus demo that runs locally from the repo
  • public CodeSearchNet metadata benchmark path with DuckDB as the first external local comparator

The earlier vector-search path is still in the repo as an experiment, but it is no longer the main product story.

Quick Example

from pathlib import Path

import balarama as br

csv_path = Path("examples/data/code_corpus_sample.csv")
explorer = br.CodeCorpusExplorer.from_csv(csv_path)

python_tests = explorer.examples(
    language="python",
    split="test",
    has_docstring=True,
    limit=3,
)

docstring_rich_train_chars = explorer.sum_code_length(
    language="python",
    split="train",
    has_docstring=True,
    min_doc_len=40,
)

top_repos = explorer.top_repos(
    has_docstring=True,
    min_doc_len=20,
    top_n=5,
)

Run It

Install the editable package into a virtualenv:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e .

For a standard release install after PyPI publish:

python -m pip install balarama

Run the code corpus sample app:

make demo-code-corpus

Run the full test suite:

make test

Run the public CodeSearchNet metadata benchmark:

make benchmark-codesearchnet-hybrid

The benchmark prepares a public CodeSearchNet metadata CSV, loads it into Balarama’s hybrid table engine, and compares repeated slice/count/sum/example/top-repo workloads against DuckDB on the same corpus.

Why This Direction

The strongest product story here is not “another database” and not “another vector store”.

It is:

  • load a large structured dataset once
  • keep it in memory
  • slice it repeatedly with indexed filters
  • reconstruct rows quickly
  • do this locally from Python without running a service

That is a better match for the original architecture and for real engineering workflows around dataset prep, eval slicing, and example selection.

Current Strengths We Intend To Preserve

  • contiguous in-memory data structures
  • explicit ownership and predictable behavior
  • sorted per-column access paths
  • stable rowid bridging rows and indexes
  • benchmarkability
  • small, understandable APIs

Non-Goals For The Main Product Story

  • no hosted service
  • no distributed clustering
  • no mutable operational database story
  • no ANN-first or vector-first product identity
  • no broad SQL engine ambitions

Repository Guide

Experimental vector-path docs remain available here:

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 Distribution

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

balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl (37.8 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for balarama-0.1.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 019de539ee3826bb9f70b2240870d055db9a612a76deee21f4be35971dfa90fd
MD5 4089860e37ef2aae9987729224fceb77
BLAKE2b-256 a14fe093dc3823c34bc1ea176be1a3288788ea08c4320626c8c0c3f25ee600ee

See more details on using hashes here.

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