| Crates.io | shardex |
| lib.rs | shardex |
| version | 0.1.0 |
| created_at | 2025-09-03 01:25:19.897794+00 |
| updated_at | 2025-09-03 01:25:19.897794+00 |
| description | A high-performance memory-mapped vector search engine with ACID transactions and incremental updates |
| homepage | https://github.com/wballard/shardex |
| repository | https://github.com/wballard/shardex |
| max_upload_size | |
| id | 1821873 |
| size | 3,613,914 |
A high-performance memory-mapped vector search engine using the ApiThing pattern for consistent, type-safe operations.
use shardex::api::{
ShardexContext, CreateIndex, AddPostings, Search,
CreateIndexParams, AddPostingsParams, SearchParams
};
use shardex::{DocumentId, Posting};
use apithing::ApiOperation;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create context
let mut context = ShardexContext::new();
// Configure and create index
let create_params = CreateIndexParams::builder()
.directory_path("./my_index".into())
.vector_size(128)
.shard_size(10000)
.batch_write_interval_ms(100)
.build()?;
CreateIndex::execute(&mut context, &create_params)?;
// Add documents
let postings = vec![Posting {
document_id: DocumentId::from_raw(1),
start: 0,
length: 100,
vector: vec![0.1; 128],
}];
AddPostings::execute(&mut context, &AddPostingsParams::new(postings)?)?;
// Search
let results = Search::execute(&mut context, &SearchParams::builder()
.query_vector(vec![0.1; 128])
.k(10)
.build()?
)?;
println!("Found {} results", results.len());
Ok(())
}
Shardex is built around three core concepts:
All operations follow the same pattern:
use apithing::ApiOperation;
let result = OperationType::execute(&mut context, ¶meters)?;
Old pattern:
let config = ShardexConfig::new().directory_path("./index");
let mut index = ShardexImpl::create(config).await?;
index.add_postings(postings).await?;
let results = index.search(&query, 10, None).await?;
New pattern:
let mut context = ShardexContext::new();
let params = CreateIndexParams::builder()
.directory_path("./index".into())
.build()?;
CreateIndex::execute(&mut context, ¶ms)?;
AddPostings::execute(&mut context, &AddPostingsParams::new(postings)?)?;
let results = Search::execute(&mut context, &SearchParams::builder()
.query_vector(query)
.k(10)
.build()?
)?;
Benefits of the new API:
For a complete migration guide, see MIGRATION.md.
Extensive configuration options for optimization:
use shardex::api::{CreateIndexParams, ShardexContext, CreateIndex};
let params = CreateIndexParams::builder()
.directory_path("./optimized_index".into())
.vector_size(768) // Vector dimensions
.shard_size(50000) // Max vectors per shard
.batch_write_interval_ms(50) // WAL batch frequency
.default_slop_factor(5) // Search breadth
.bloom_filter_size(2048) // Bloom filter size
.build()?;
let mut context = ShardexContext::new();
CreateIndex::execute(&mut context, ¶ms)?;
The repository includes comprehensive examples demonstrating the ApiThing pattern:
Run examples with:
cargo run --example basic_usage
cargo run --example configuration
cargo run --example monitoring
Shardex delivers high performance through:
Benchmarks (1M vectors, 384 dimensions, Intel i7, 32GB RAM):
Performance varies based on hardware, data characteristics, and configuration. Run your own benchmarks for accurate measurements.
Contributions are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.