M2M EBM Vector Database โ Energy-Based Model storage with full CRUD, WAL persistence, REST API, and Self-Organized Criticality
Project description
M2M Vector Search
๐ Performance Highlights
Real Benchmark Results (DBpedia 1M Dataset)
| Metric | M2M | Linear Scan | Improvement |
|---|---|---|---|
| Throughput | 104.9 QPS | 48.1 QPS | +118% faster |
| Mean Latency | 9.53ms | 20.79ms | 54% faster |
| Median Latency | 9.53ms | 20.60ms | 54% faster |
| P95 Latency | 10.08ms | 22.52ms | 55% faster |
| P99 Latency | 11.14ms | 24.00ms | 54% faster |
| Min Latency | 8.47ms | 19.37ms | 56% faster |
| Max Latency | 16.02ms | 28.01ms | 43% faster |
Dataset: 10,000 vectors ยท 640D (truncated from 3,072D)
Hardware: AMD Ryzen 5 3400G ยท 32GB RAM ยท CPU Mode
Test Coverage: 100% (12/12 tests passing)
๐ฏ Key Features
โ Core Capabilities
- Full CRUD Operations โ Add, update, delete with metadata
- Adaptive Indexing โ Automatic LSH fallback for uniform distributions
- Metadata Filtering โ Complex queries with multiple conditions
- Document Storage โ Store and retrieve text alongside vectors
- WAL Persistence โ Durable write-ahead logging
- REST API โ Production-ready HTTP interface
โ Advanced Features
- Energy-Based Models (EBM) โ Uncertainty quantification
- Self-Organized Criticality (SOC) โ Autonomous reorganization
- Knowledge Gap Detection โ Identify unexplored regions
- Exploration Suggestions โ Intelligent data collection guidance
- 3-Tier Memory โ VRAM/RAM/SSD hierarchy
๐๏ธ Architecture
Layer Overview
Layer 1: Public API
- SimpleVectorDB & AdvancedVectorDB
- User-facing CRUD operations
Layer 2: M2M Engine
- Core orchestration
- Query optimization
- Index management
Layer 3: Core Components
- SplatStore: Gaussian Splat storage (ฮผ, ฮฑ, ฮบ)
- HRM2 Engine: Hierarchical 2-level clustering
- EnergyFunction: Riemannian geometry energy landscape
Layer 4: Storage & Indexing
- LSH Index: Cross-polytope approximate search
- WAL Persistence: SQLite-backed write-ahead log
Side: EBM Layer
- Uncertainty quantification
- SOC engine & knowledge gap detection
- Exploration strategies
Core Components Table
| Component | Purpose | Technology |
|---|---|---|
| SimpleVectorDB | Public API for vector operations | Python |
| M2MEngine | Core engine orchestrating all operations | Python + NumPy |
| SplatStore | Gaussian Splat storage (ฮผ, ฮฑ, ฮบ) | NumPy arrays |
| HRM2Engine | Hierarchical retrieval (2-level clustering) | MiniBatchKMeans |
| EnergyFunction | Energy landscape computation | Riemannian geometry |
| LSH Index | Approximate NN for uniform data | Cross-polytope LSH |
๐ Latency Analysis
Complete Latency Breakdown
| Percentile | M2M | Linear Scan | Speedup |
|---|---|---|---|
| Min | 8.47ms | 19.37ms | -56% |
| Mean | 9.53ms | 20.79ms | -54% |
| Median | 9.53ms | 20.60ms | -54% |
| P95 | 10.08ms | 22.52ms | -55% |
| P99 | 11.14ms | 24.00ms | -54% |
| Max | 16.02ms | 28.01ms | -43% |
Result: M2M maintains sub-10ms average with highly predictable tail latency.
๐ Performance Comparison
M2M vs Linear Scan (Real Baseline)
| System | Throughput | Mean Latency | P95 Latency | P99 Latency |
|---|---|---|---|---|
| Linear Scan | 48.1 QPS | 20.79ms | 22.52ms | 24.00ms |
| M2M | 104.9 QPS | 9.53ms | 10.08ms | 11.14ms |
Result: M2M is 2.18ร faster in throughput and 54% lower in mean latency vs. linear scan.
๐ Dataset Statistics
DBpedia 1M Dataset
| Property | Value |
|---|---|
| Source | HuggingFace BeIR/dbpedia-entity |
| Embedding Model | OpenAI text-embedding-3-large |
| Original Dimension | 3,072D |
| Truncated Dimension | 640D (20.8% of original) |
| Documents Tested | 10,000 (subset of available) |
| Test Queries | 1,000 queries, k=10 |
| Memory Footprint | 24.4 MB |
| Ingestion Rate | 1,528 docs/sec |
| Ingestion Time | 6.54s for 10K docs |
๐งช Test Coverage
All Tests Passing (12/12 โ 100%)
| Component | Status |
|---|---|
| SplatStore | โ PASS |
| HRM2Engine | โ PASS |
| EnergyFunction | โ PASS |
| EBM Components | โ PASS |
| Storage & WAL | โ PASS |
| LSH Index | โ PASS |
| SimpleVectorDB | โ PASS |
| AdvancedVectorDB | โ PASS |
| Integrations | โ PASS |
| Large-scale Ingestion | โ PASS |
| Search Performance | โ PASS |
| Memory Efficiency | โ PASS |
๐ Quick Start
Installation
# Clone repository
git clone https://github.com/schwabauerbriantomas-gif/m2m-vector-search.git
cd m2m-vector-search
# Install dependencies
pip install -r requirements.txt
# Install package
pip install -e .
Basic Usage
from m2m import SimpleVectorDB
import numpy as np
# Initialize database
db = SimpleVectorDB(latent_dim=768, mode='standard')
# Add documents with metadata
vectors = np.random.randn(1000, 768).astype(np.float32)
metadata = [{'category': 'tech', 'source': 'blog'} for _ in range(1000)]
documents = [f'Document {i}' for i in range(1000)]
db.add(
ids=[f'doc{i}' for i in range(1000)],
vectors=vectors,
metadata=metadata,
documents=documents
)
# Search with filters
query = np.random.randn(768).astype(np.float32)
results = db.search(
query,
k=10,
filter={'category': {'$eq': 'tech'}},
include_metadata=True
)
# CRUD operations
db.update('doc1', metadata={'category': 'updated'})
db.delete(id='doc2')
db.save('./backup')
๐ Documentation
| Document | Description |
|---|---|
| USER_GUIDE.md | Complete usage guide with examples |
| DEVELOPER_DOCS.md | Architecture & internals |
| BENCHMARK_REPORT.md | Professional benchmark results |
| CONFIGURATION.md | Configuration reference |
| TESTING_REPORT.md | Test validation report |
| EXECUTIVE_SUMMARY.md | Executive summary |
๐๏ธ Configuration
Development (Edge Mode)
db = SimpleVectorDB(latent_dim=768, mode='edge')
Use for: Testing, development, edge devices.
Production (Standard Mode)
db = SimpleVectorDB(
latent_dim=768,
mode='standard',
storage_path='./data/m2m',
enable_wal=True
)
Use for: Production deployment with persistence.
Research (EBM Mode)
db = AdvancedVectorDB(
latent_dim=768,
enable_soc=True,
enable_energy_features=True
)
Use for: Research, adaptive systems, autonomous agents.
๐ Project Structure
m2m-vector-search/
โโโ src/m2m/ # Source code
โ โโโ __init__.py # Main API exports
โ โโโ engine.py # M2MEngine core
โ โโโ splats.py # SplatStore (Gaussian Splats)
โ โโโ hrm2_engine.py # Hierarchical Retrieval
โ โโโ energy.py # Energy functions
โ โโโ lsh_index.py # Cross-polytope LSH
โ โโโ ebm/ # Energy-Based Model
โ โ โโโ energy_api.py # Energy API
โ โ โโโ exploration.py # Exploration strategies
โ โ โโโ soc.py # Self-Organized Criticality
โ โโโ storage/ # Persistence layer
โ โ โโโ persistence.py # M2MPersistence
โ โ โโโ wal.py # Write-Ahead Log
โ โโโ cluster/ # Distributed cluster
โ โโโ api/ # REST API
โ
โโโ tests/ # Unit tests (12/12 passing)
โโโ integrations/ # LangChain, LlamaIndex
โโโ examples/ # Usage examples
โโโ benchmarks/ # Performance tests
โ
โโโ assets/ # Charts and images
โ โโโ performance_overview.png
โ โโโ latency_distribution.png
โ โโโ throughput_comparison.png
โ โโโ architecture_overview.png
โ โโโ dataset_statistics.png
โ โโโ test_coverage.png
โ
โโโ benchmark_results.json # Raw M2M benchmark data
โโโ linear_scan_baseline.json # Raw linear scan baseline
โโโ README.md # This file
โ๏ธ Requirements
Minimum
- Python 3.10+
- NumPy
- scikit-learn
- SQLite3
Recommended
- 4+ CPU cores
- 16GB RAM
- SSD storage
Optional
- Vulkan SDK (for GPU acceleration)
- PyTorch (for advanced features)
๐ง Integration Examples
LangChain
from m2m.integrations.langchain import M2MVectorStore
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
vectorstore = M2MVectorStore(embedding=embeddings, latent_dim=1536)
from langchain.chains import RetrievalQA
qa = RetrievalQA.from_chain_type(
llm=llm,
retriever=vectorstore.as_retriever()
)
REST API
# Start server
uvicorn m2m.api.coordinator_api:app --host 0.0.0.0 --port 8000
import requests
# Create collection
requests.post('http://localhost:8000/collections', json={
'name': 'documents',
'dimension': 768
})
# Search
response = requests.post('http://localhost:8000/collections/documents/search', json={
'query': query.tolist(),
'k': 10
})
๐ Raw Benchmark Data
Test Configuration
Dataset : DBpedia 1M (OpenAI text-embedding-3-large)
Documents : 10,000
Dimension : 640D (truncated from 3,072D)
Queries : 1,000
k : 10
Mode : Standard (CPU)
Hardware : AMD Ryzen 5 3400G, 32GB RAM
Date : 2026-03-13
M2M Results (benchmark_results.json)
{
"ingestion": {
"num_documents": 10000,
"time_sec": 6.54,
"throughput_docs_per_sec": 1528.4
},
"search": {
"num_queries": 1000,
"k": 10,
"qps": 104.9,
"mean_ms": 9.53,
"median_ms": 9.53,
"p95_ms": 10.08,
"p99_ms": 11.14,
"min_ms": 8.47,
"max_ms": 16.02
},
"memory_mb": 24.4
}
Linear Scan Baseline (linear_scan_baseline.json)
{
"method": "linear_scan",
"num_queries": 1000,
"k": 10,
"qps": 48.1,
"mean_ms": 20.79,
"median_ms": 20.60,
"p95_ms": 22.52,
"p99_ms": 24.00,
"min_ms": 19.37,
"max_ms": 28.01
}
๐ฏ Use Cases
โ Recommended For
- RAG Systems โ Retrieval-Augmented Generation
- Semantic Search โ Document similarity search
- Recommendation Engines โ Content-based filtering
- Anomaly Detection โ Outlier identification
- Autonomous Agents โ Adaptive knowledge bases
โ ๏ธ Not Recommended For
- Exact nearest neighbor (use FAISS)
- Billions of vectors (use distributed systems)
- Real-time streaming (use specialized systems)
๐บ๏ธ Roadmap
Current (v2.0.3)
- โ Core functionality (CRUD + search)
- โ EBM features
- โ WAL persistence
- โ REST API
- โ 100% test coverage (12/12)
Near-term
- ๐ GPU acceleration (Vulkan)
- ๐ Distributed cluster mode
- ๐ Query optimization
- ๐ Auto-scaling
Long-term
- ๐ Multi-modal support
- ๐ Federated learning
- ๐ Edge deployment
- ๐ Real-time streaming
๐ License
GNU Affero General Public License v3.0 (AGPLv3) โ see LICENSE for details.
๐ค Contributing
Contributions welcome! Please read:
- Architecture: DEVELOPER_DOCS.md
- Configuration: CONFIGURATION.md
- Testing:
python test_complete_validated.py
๐ Contact
- Repository: https://github.com/schwabauerbriantomas-gif/m2m-vector-search
- Issues: GitHub Issues
- Documentation: See documentation files above
โ Status
Production Ready
- โ Validated with real DBpedia 1M dataset (OpenAI embeddings)
- โ 100% test coverage (12/12 tests passing)
- โ 2.18ร faster throughput vs. linear scan baseline
- โ 54% lower mean latency vs. linear scan
- โ Ingestion: 1,528 docs/sec
- โ Ready for immediate deployment
Benchmarked on DBpedia 1M ยท AMD Ryzen 5 3400G ยท CPU Mode ยท 2026-03-13
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
Built Distribution
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 m2m_vector_search-2.0.3.tar.gz.
File metadata
- Download URL: m2m_vector_search-2.0.3.tar.gz
- Upload date:
- Size: 110.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06827207de411cd6441a47da021f9a98eafb49d17c534225bfc47b565f408291
|
|
| MD5 |
790fdc50c253a994a017d8b2bcd0bdf1
|
|
| BLAKE2b-256 |
be8b2b223b56baa44099e488325c0b0cd5ab1725d853b700d78144b95c1cc2d9
|
Provenance
The following attestation bundles were made for m2m_vector_search-2.0.3.tar.gz:
Publisher:
publish.yml on schwabauerbriantomas-gif/m2m-vector-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
m2m_vector_search-2.0.3.tar.gz -
Subject digest:
06827207de411cd6441a47da021f9a98eafb49d17c534225bfc47b565f408291 - Sigstore transparency entry: 1097070740
- Sigstore integration time:
-
Permalink:
schwabauerbriantomas-gif/m2m-vector-search@ae0623f44e76eaa894b546cef1bd91a9e6d8dd4d -
Branch / Tag:
refs/tags/2.0.3 - Owner: https://github.com/schwabauerbriantomas-gif
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae0623f44e76eaa894b546cef1bd91a9e6d8dd4d -
Trigger Event:
release
-
Statement type:
File details
Details for the file m2m_vector_search-2.0.3-py3-none-any.whl.
File metadata
- Download URL: m2m_vector_search-2.0.3-py3-none-any.whl
- Upload date:
- Size: 111.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c61dd842eda41872adae3a092a7e7ffe22785f590371f8dc00c9a333246fb8bd
|
|
| MD5 |
5c8dc4af0bc41e61a691e59492049acf
|
|
| BLAKE2b-256 |
ab4c592cfe6e301fda939831d3fbceea57daf28802ca70824c7cd4e787e1d930
|
Provenance
The following attestation bundles were made for m2m_vector_search-2.0.3-py3-none-any.whl:
Publisher:
publish.yml on schwabauerbriantomas-gif/m2m-vector-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
m2m_vector_search-2.0.3-py3-none-any.whl -
Subject digest:
c61dd842eda41872adae3a092a7e7ffe22785f590371f8dc00c9a333246fb8bd - Sigstore transparency entry: 1097070744
- Sigstore integration time:
-
Permalink:
schwabauerbriantomas-gif/m2m-vector-search@ae0623f44e76eaa894b546cef1bd91a9e6d8dd4d -
Branch / Tag:
refs/tags/2.0.3 - Owner: https://github.com/schwabauerbriantomas-gif
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae0623f44e76eaa894b546cef1bd91a9e6d8dd4d -
Trigger Event:
release
-
Statement type: