Skip to main content

Lightweight vector database optimized for AWS Lambda with lexical, semantic, and hybrid search

Project description

PeachBase

Lightweight vector database optimized for AWS Lambda with lexical, semantic, and hybrid search.

PeachBase is a high-performance, serverless-friendly vector database designed for fast cold starts and minimal dependencies. It combines lexical search (BM25), semantic search (SIMD-accelerated vectors), and hybrid search (Reciprocal Rank Fusion) in a single, easy-to-use package.

Features

  • ๐Ÿš€ Fast Cold Starts: Optimized for AWS Lambda with memory-mapped loading and minimal initialization
  • ๐Ÿ” Three Search Modes: Lexical (BM25), semantic (vector), and hybrid (RRF)
  • โšก SIMD Acceleration: AVX2/AVX-512 optimized vector operations for blazing-fast similarity search
  • ๐Ÿ“ฆ Minimal Dependencies: No numpy, pandas, scikit-learn, or pyarrow - only boto3 for S3
  • โ˜๏ธ S3 Native: Efficiently read/write collections from S3 with byte-range requests
  • ๐ŸŽฏ Metadata Filtering: MongoDB-like query syntax for filtering results
  • ๐Ÿ’พ In-Memory Storage: Fast access with memory-mapped binary format
  • ๐Ÿ Python 3.11+: Modern Python with type hints

Installation

From PyPI

pip install peachbase

From Source

git clone https://github.com/PeachstoneAI/peachbase.git
cd peachbase
pip install -e .

Quick Start

import peachbase

# Connect to database (local or S3)
db = peachbase.connect("./my_database")  # Local
# db = peachbase.connect("s3://my-bucket/my_db")  # S3

# Create a collection
collection = db.create_collection("articles", dimension=384)

# Add documents with embeddings
collection.add([
    {
        "id": "doc1",
        "text": "Machine learning is fascinating",
        "vector": [0.1, 0.2, ...],  # Your embeddings (384-dim)
        "metadata": {"category": "tech", "year": 2024}
    }
])

# Semantic search
results = collection.search(
    query_vector=[0.3, 0.1, ...],
    limit=10
)

for result in results.to_list():
    print(f"{result['id']}: {result['text']} (score: {result['score']:.4f})")

Search Modes

1. Semantic Search (Vector Similarity)

results = collection.search(
    query_vector=[0.1, 0.2, ...],
    mode="semantic",
    metric="cosine",  # or "l2", "dot"
    limit=10
)

2. Lexical Search (BM25)

results = collection.search(
    query_text="machine learning",
    mode="lexical",
    limit=10
)

3. Hybrid Search (Best of Both)

results = collection.search(
    query_text="machine learning",
    query_vector=[0.1, 0.2, ...],
    mode="hybrid",
    alpha=0.5,  # 0=semantic only, 1=lexical only
    limit=10
)

Metadata Filtering

results = collection.search(
    query_vector=[0.1, ...],
    filter={
        "category": "tech",
        "year": {"$gte": 2023, "$lte": 2024},
        "tags": {"$in": ["ai", "ml"]}
    },
    limit=10
)

Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $and, $or, $not

AWS Lambda Deployment

1. Package Your Function

# Build the package with C extensions
pip install peachbase -t ./package
cd package
zip -r ../lambda_function.zip .
cd ..
zip -g lambda_function.zip lambda_function.py

2. Lambda Function Example

import json
import peachbase

def lambda_handler(event, context):
    # Connect to S3-backed database
    db = peachbase.connect("s3://my-bucket/peachbase")

    # Open collection
    collection = db.open_collection("articles")

    # Search
    results = collection.search(
        query_vector=event["query_vector"],
        limit=10
    )

    return {
        "statusCode": 200,
        "body": json.dumps({
            "results": [
                {"id": r["id"], "text": r["text"], "score": r["score"]}
                for r in results.to_list()
            ]
        })
    }

3. Lambda Configuration

  • Memory: 1024 MB - 3008 MB recommended
    • Lambda allocates vCPUs proportionally to memory (1,769 MB = 1 full vCPU)
    • More memory enables parallel SIMD operations and faster collection loading
    • For collections > 50K docs, use 2048+ MB for optimal performance
  • Timeout: 10-30 seconds (first cold start may be slower)
  • Runtime: Python 3.11, 3.12, 3.13, or 3.14 (latest)
  • Architecture: x86_64 (required for AVX2/AVX-512 SIMD acceleration)

4. Optimization Tips

  • S3 Caching: Collections loaded from S3 are cached in /tmp between invocations. Subsequent warm invocations skip the S3 download entirely, reducing latency from ~800ms to ~100ms.

  • Package Size: Keep deployment packages under 50 MB for optimal cold start times. Larger packages increase initialization time as Lambda extracts and loads your code.

  • Strip Debug Symbols: Run strip *.so on compiled extensions before packaging. This removes debug information and can reduce .so file sizes by 50-80%, directly improving cold start time.

  • Provisioned Concurrency: For latency-sensitive applications, enable provisioned concurrency. Lambda pre-initializes execution environments, eliminating cold starts entirely and providing consistent sub-100ms response times.

  • ARM vs x86: While ARM (Graviton) offers better price-performance for general workloads, PeachBase requires x86_64 for AVX2/AVX-512 SIMD instructions. The vector operation speedup outweighs the ARM cost savings.

Compilation from Source

Prerequisites

  • Python 3.11+
  • C compiler (gcc, clang, or MSVC)
  • Python development headers

Linux/macOS

# Install build dependencies
pip install build wheel

# Compile
python -m build

# Install
pip install dist/peachbase-*.whl

For AWS Lambda (Cross-Compilation)

# Use Docker to build for Lambda environment
docker run --rm -v $(pwd):/workspace \
    public.ecr.aws/lambda/python:3.11 \
    bash -c "cd /workspace && pip install build && python -m build"

API Reference

Database

db = peachbase.connect(uri)  # Local path or s3://bucket/path
db.create_collection(name, dimension, overwrite=False)
db.open_collection(name)
db.list_collections()
db.drop_collection(name)

Collection

collection.add(documents)  # Add documents
collection.get(doc_id)  # Get by ID
collection.delete(doc_id)  # Delete by ID
collection.search(...)  # Search (see modes above)
collection.save()  # Persist to disk/S3
Collection.load(name, database)  # Load from disk/S3

Query Results

results.to_list()  # List of dicts
results.to_dict()  # Dict with metadata
len(results)  # Number of results
results[0]  # Access by index
for result in results:  # Iterate
    print(result)

Performance

Benchmarks on AWS Lambda (Python 3.11, 1024 MB, x86_64):

Operation Collection Size Latency
Cold Start 10K docs ~1.5s
Warm Start 10K docs ~50ms
Semantic Search 10K docs ~30ms
Hybrid Search 10K docs ~45ms
S3 Load (first) 10K docs ~800ms
S3 Load (cached) 10K docs ~100ms

Benchmarks with 384-dimensional vectors on c6i.large equivalent Lambda

Architecture

PeachBase
โ”œโ”€โ”€ Binary Format (.pdb)
โ”‚   โ”œโ”€โ”€ Header (256 bytes)
โ”‚   โ”œโ”€โ”€ Vector Data (SIMD-aligned)
โ”‚   โ”œโ”€โ”€ Text Data
โ”‚   โ”œโ”€โ”€ Metadata (JSON)
โ”‚   โ””โ”€โ”€ BM25 Index
โ”œโ”€โ”€ C Extensions
โ”‚   โ”œโ”€โ”€ SIMD Operations (AVX2/AVX-512)
โ”‚   โ””โ”€โ”€ BM25 Scoring
โ””โ”€โ”€ Python Layer
    โ”œโ”€โ”€ Database & Collection
    โ”œโ”€โ”€ Search Modes
    โ””โ”€โ”€ S3 Integration

Examples

See the examples/ directory for more:

  • basic_usage.py - Getting started with PeachBase
  • hybrid_search.py - Comparing search modes
  • lambda_deployment.py - AWS Lambda function example

Limitations

  • Collection Size: Optimized for < 100K vectors (brute-force search)
  • Dimension: Tested with 384-1536 dimensional vectors
  • Dependencies: Requires boto3 for S3 (included in Lambda by default)
  • Platform: Best performance on x86_64 with AVX2 support

Roadmap

  • Approximate Nearest Neighbor (HNSW/IVF) for large collections
  • Multi-vector documents
  • Batch operations API
  • Additional distance metrics (Manhattan, Hamming)
  • Query result caching
  • ARM/NEON SIMD support

Contributing

Contributions are welcome! Please see Contributing Guide for guidelines.

License

MIT License - see LICENSE for details.

Acknowledgments

  • Inspired by LanceDB for API design
  • BM25 algorithm implementation follows standard Okapi BM25
  • RRF (Reciprocal Rank Fusion) based on research papers and OpenSearch implementation

Documentation

For complete documentation, see the docs/ directory:

๐Ÿš€ Getting Started

๐Ÿ“– User Guides

๐Ÿ“‹ Reference

See Full Documentation Index for all available docs.

Support


Made with ๐Ÿ‘ for serverless vector search

Project details


Download files

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

Source Distribution

peachbase-0.4.2.tar.gz (62.0 kB view details)

Uploaded Source

Built Distributions

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

peachbase-0.4.2-cp313-cp313-win_amd64.whl (50.0 kB view details)

Uploaded CPython 3.13Windows x86-64

peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (139.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl (41.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl (43.1 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

File details

Details for the file peachbase-0.4.2.tar.gz.

File metadata

  • Download URL: peachbase-0.4.2.tar.gz
  • Upload date:
  • Size: 62.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for peachbase-0.4.2.tar.gz
Algorithm Hash digest
SHA256 4004f89c086dfd0f732c48b1b076567b31144a5f603f730ea5ea717d66e9f541
MD5 2113dba65e649c66e2e2fefaac21b602
BLAKE2b-256 3d4cda43f2ccfcc48f79d20cbf9559e89d478df995ac7cb3ae28c5e7f16f09c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for peachbase-0.4.2.tar.gz:

Publisher: release.yml on PeachstoneAI/PeachBase

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

File details

Details for the file peachbase-0.4.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: peachbase-0.4.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 50.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for peachbase-0.4.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 27e2362e360c3fdbe79ea29e65826983877b5c811bbfed9af9139718e172a733
MD5 a63adfa3c96193980489d32aca6e999d
BLAKE2b-256 fb83c10e0d4c80c7f752e98b6f48d9e7e69d74bda849e4ca3db684533d56525f

See more details on using hashes here.

Provenance

The following attestation bundles were made for peachbase-0.4.2-cp313-cp313-win_amd64.whl:

Publisher: release.yml on PeachstoneAI/PeachBase

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

File details

Details for the file peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15f63879b8bbf4e83ef81d805214d4fe1d1dacb880ab02cda65e40d8f4cadb96
MD5 770b41383c16b7a2167bc1c37bbeec5a
BLAKE2b-256 87c127c157353552aeeb68626d859a2db28a876dbe6347fc2f3d2f6d60d8cc46

See more details on using hashes here.

Provenance

The following attestation bundles were made for peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on PeachstoneAI/PeachBase

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

File details

Details for the file peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19f762c86d7be7199aebbb683aaa0bda082e1e5dfc0eab71417e203b3fe2a725
MD5 d76a20c11e45acf2c016c7583601fb5b
BLAKE2b-256 4e4fc5d629a04c00ee4e9932676c81eadbd3ec1f3bcc9af545255129d2e15b28

See more details on using hashes here.

Provenance

The following attestation bundles were made for peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on PeachstoneAI/PeachBase

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

File details

Details for the file peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2748c4d0fdc838b76ec1f92021ae587918ddff353df15d1b69cf4344c8ba722c
MD5 2734c1cef00587d547572c8c68ee7f15
BLAKE2b-256 ba62277bcbefefe62a6e449771b890b19a8992a4cb2d4b3cfbf9f97cd4d08a0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: release.yml on PeachstoneAI/PeachBase

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