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
/tmpbetween 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 *.soon compiled extensions before packaging. This removes debug information and can reduce.sofile 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 PeachBasehybrid_search.py- Comparing search modeslambda_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
- Installation Guide - Install PeachBase in 30 seconds
- Quick Start - Your first search in 5 minutes
- Basic Concepts - Core concepts and terminology
๐ User Guides
- Search Modes Guide - Semantic, lexical, and hybrid search explained
- Understanding Scores - How scores are calculated in each mode
- Building from Source - Compile with/without OpenMP
- Performance Optimizations - Detailed optimization analysis with benchmarks
๐ Reference
- API Reference - Complete API documentation
- Performance Benchmarks - Detailed performance metrics
- Architecture - How PeachBase works internally
See Full Documentation Index for all available docs.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ๐ for serverless vector search
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4004f89c086dfd0f732c48b1b076567b31144a5f603f730ea5ea717d66e9f541
|
|
| MD5 |
2113dba65e649c66e2e2fefaac21b602
|
|
| BLAKE2b-256 |
3d4cda43f2ccfcc48f79d20cbf9559e89d478df995ac7cb3ae28c5e7f16f09c9
|
Provenance
The following attestation bundles were made for peachbase-0.4.2.tar.gz:
Publisher:
release.yml on PeachstoneAI/PeachBase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
peachbase-0.4.2.tar.gz -
Subject digest:
4004f89c086dfd0f732c48b1b076567b31144a5f603f730ea5ea717d66e9f541 - Sigstore transparency entry: 830850430
- Sigstore integration time:
-
Permalink:
PeachstoneAI/PeachBase@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/PeachstoneAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27e2362e360c3fdbe79ea29e65826983877b5c811bbfed9af9139718e172a733
|
|
| MD5 |
a63adfa3c96193980489d32aca6e999d
|
|
| BLAKE2b-256 |
fb83c10e0d4c80c7f752e98b6f48d9e7e69d74bda849e4ca3db684533d56525f
|
Provenance
The following attestation bundles were made for peachbase-0.4.2-cp313-cp313-win_amd64.whl:
Publisher:
release.yml on PeachstoneAI/PeachBase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
peachbase-0.4.2-cp313-cp313-win_amd64.whl -
Subject digest:
27e2362e360c3fdbe79ea29e65826983877b5c811bbfed9af9139718e172a733 - Sigstore transparency entry: 830850496
- Sigstore integration time:
-
Permalink:
PeachstoneAI/PeachBase@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/PeachstoneAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Trigger Event:
release
-
Statement type:
File details
Details for the file peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 139.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15f63879b8bbf4e83ef81d805214d4fe1d1dacb880ab02cda65e40d8f4cadb96
|
|
| MD5 |
770b41383c16b7a2167bc1c37bbeec5a
|
|
| BLAKE2b-256 |
87c127c157353552aeeb68626d859a2db28a876dbe6347fc2f3d2f6d60d8cc46
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
peachbase-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
15f63879b8bbf4e83ef81d805214d4fe1d1dacb880ab02cda65e40d8f4cadb96 - Sigstore transparency entry: 830850452
- Sigstore integration time:
-
Permalink:
PeachstoneAI/PeachBase@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/PeachstoneAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Trigger Event:
release
-
Statement type:
File details
Details for the file peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 41.5 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19f762c86d7be7199aebbb683aaa0bda082e1e5dfc0eab71417e203b3fe2a725
|
|
| MD5 |
d76a20c11e45acf2c016c7583601fb5b
|
|
| BLAKE2b-256 |
4e4fc5d629a04c00ee4e9932676c81eadbd3ec1f3bcc9af545255129d2e15b28
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
peachbase-0.4.2-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
19f762c86d7be7199aebbb683aaa0bda082e1e5dfc0eab71417e203b3fe2a725 - Sigstore transparency entry: 830850468
- Sigstore integration time:
-
Permalink:
PeachstoneAI/PeachBase@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/PeachstoneAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Trigger Event:
release
-
Statement type:
File details
Details for the file peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl.
File metadata
- Download URL: peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl
- Upload date:
- Size: 43.1 kB
- Tags: CPython 3.13, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2748c4d0fdc838b76ec1f92021ae587918ddff353df15d1b69cf4344c8ba722c
|
|
| MD5 |
2734c1cef00587d547572c8c68ee7f15
|
|
| BLAKE2b-256 |
ba62277bcbefefe62a6e449771b890b19a8992a4cb2d4b3cfbf9f97cd4d08a0f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
peachbase-0.4.2-cp313-cp313-macosx_10_13_x86_64.whl -
Subject digest:
2748c4d0fdc838b76ec1f92021ae587918ddff353df15d1b69cf4344c8ba722c - Sigstore transparency entry: 830850471
- Sigstore integration time:
-
Permalink:
PeachstoneAI/PeachBase@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/PeachstoneAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6fd3be5910c9be7069ef75693d5dbc72d8a666d -
Trigger Event:
release
-
Statement type: