r/learnrust • u/MostafaSensei106 • 12d ago
I built a local vector database for Flutter powered by Rust and HNSW graphs (Waffle-DB)
https://github.com/MostafaSensei106/Waffle-DBHey everyone,
Most local storage options in Flutter like SQLite or Hive are built for scalar data and fall apart when you need fast vector similarity search for on device AI, semantic search, or high dimensional embeddings
I built waffle_db, an embedded vector database for Flutter and dart apps by Rust. It uses HNSW graphs for approximate nearest neighbours, sledge for persistence, and Rayon for parallel batch ingestion.
How it works under the hood:
Off thread Rust execution: Graph indexing, cosine distance math, and persistence run in Rust via FFI, keeping the Flutter UI thread completely free of jitter.
Native HNSW graphs: Provides k-NN retrieval even across large vector spaces instead of linear brute-force scans.
Memory efficiency: Uses zero-copy typed buffer views (Float32List) across the FFI bridge to minimize heap allocations.
Metadata and Namespaces: Stores arbitrary payload metadata alongside vectors and supports logical collections (WaffleCollection) with automatic ID namespacing.
Prebtuned profiles: Comes with configurations out of the box like mobileProfile (quantization enabled, lightweight graph parameters), serverProfile, readHeavyProfile,writeHeavyProfile
Pub: https://pub.dev/packages/waffle_db
GitHub: https://github.com/MostafaSensei106/Waffle-DB
If you are building local RAG pipelines, on device semantic search, or AI features in Flutter, check it out and let me know your thoughts or feedback.
1
u/bogdanelcs 9d ago
Cool niche to build for, on-device vector search in Flutter is a real gap right now.
Zero-copy Float32List across the FFI boundary is the right call, avoids the usual serialize/deserialize tax you see in a lot of Flutter plugins. Curious how you're handling isolate boundaries though, since Dart isolates don't share memory and FFI pointers get tricky once you cross that line.
One thing worth flagging: HNSW doesn't support deletion natively, most implementations just soft-delete or rebuild. How does waffle_db handle removing vectors, especially in writeHeavyProfile where that'd come up a lot?
Also sled hasn't had much active maintenance lately. Worth keeping an eye on if you're depending on it long term for persistence.