Skip to content

Commit 2b0e5e7

Browse files
matte1782claude
andcommitted
chore(w47): rebuild pkg/ with PQ WASM exports (bundler target)
wasm-pack build output updated to include trainPq, encodePq, pqSearch, and PqCodebookHandle exports. Binary 602→623 KB. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8e0e112 commit 2b0e5e7

7 files changed

Lines changed: 177 additions & 4493 deletions

File tree

pkg/.gitignore

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
*
2-
# Allow langchain adapter source (not build output)
3-
!langchain/
4-
!langchain/README.md
5-
!langchain/package.json
6-
!langchain/tsconfig.json
7-
!langchain/tsup.config.ts
8-
!langchain/vitest.config.ts
9-
!langchain/src/
10-
!langchain/src/**
11-
!langchain/tests/
12-
!langchain/tests/**
1+
*

pkg/README.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,32 +271,43 @@ config.quantized = true; // Enable SQ8 quantization
271271

272272
Brute-force exact nearest neighbor search for small datasets. No graph overhead, 100% recall guarantee.
273273

274-
```rust
274+
```rust,ignore
275275
use edgevec::{FlatIndex, FlatIndexConfig, DistanceMetric};
276276
277277
let config = FlatIndexConfig::new(768)
278278
.with_metric(DistanceMetric::Cosine)
279279
.with_capacity(10_000);
280280
let mut index = FlatIndex::new(config);
281281
282+
// Insert vectors
282283
let id = index.insert(&embedding)?;
284+
285+
// Exact search (100% recall)
283286
let results = index.search(&query, 10)?;
287+
288+
// Persistence via snapshot
289+
let snapshot = index.to_snapshot()?;
290+
let restored = FlatIndex::from_snapshot(&snapshot)?;
284291
```
285292

293+
**When to use FlatIndex:** Datasets under ~50K vectors where exact recall matters more than speed.
294+
286295
### Sparse Vectors (v0.9.0)
287296

288297
CSR-format sparse vector storage with inverted index for fast keyword-style retrieval.
289298

290-
```rust
299+
```rust,ignore
291300
use edgevec::SparseVector;
292301
use edgevec::sparse::{SparseStorage, SparseSearcher};
293302
303+
// Create a sparse vector (e.g., BM25 term weights)
294304
let sv = SparseVector::new(
295305
vec![10, 42, 999], // term indices
296306
vec![0.8, 1.2, 0.3], // term weights
297307
30_000, // vocabulary size
298308
)?;
299309
310+
// Store and search
300311
let mut storage = SparseStorage::new();
301312
let id = storage.insert(&sv)?;
302313
@@ -306,33 +317,50 @@ let results = searcher.search(&query_sv, 10);
306317

307318
### Hybrid Search (v0.9.0)
308319

309-
Combine dense (HNSW) and sparse retrieval with RRF or linear fusion.
320+
Combine dense (HNSW) and sparse retrieval with Reciprocal Rank Fusion (RRF) or linear fusion.
310321

311-
```rust
322+
```rust,ignore
312323
use edgevec::hybrid::{HybridSearcher, HybridSearchConfig, FusionMethod};
313324
325+
// Set up: HNSW index + sparse storage already populated
314326
let searcher = HybridSearcher::new(&hnsw_index, &dense_storage, &sparse_storage);
315327
316328
let config = HybridSearchConfig::new(
317-
50, 50, 10,
318-
FusionMethod::Rrf { k: 60 },
329+
50, // dense_k: candidates from HNSW
330+
50, // sparse_k: candidates from sparse
331+
10, // final_k: results after fusion
332+
FusionMethod::Rrf { k: 60 }, // RRF with k=60
319333
);
320334
321335
let results = searcher.search(&dense_query, &sparse_query, &config)?;
336+
for r in &results {
337+
println!("ID: {}, score: {:.4}, dense_rank: {:?}, sparse_rank: {:?}",
338+
r.id, r.score, r.dense_rank, r.sparse_rank);
339+
}
322340
```
323341

324342
### BinaryFlatIndex (v0.9.0)
325343

326-
Native binary vector storage with Hamming distance search. 32x memory reduction.
344+
Native binary vector storage with Hamming distance search. 32x memory reduction, sub-microsecond inserts.
327345

328-
```rust
346+
```rust,ignore
329347
use edgevec::BinaryFlatIndex;
330348
349+
// 768-bit binary vectors (96 bytes each)
331350
let mut index = BinaryFlatIndex::new(768)?;
351+
352+
// Insert packed binary vectors
332353
let id = index.insert(&binary_vector)?;
354+
355+
// Hamming distance search
333356
let results = index.search(&query, 10)?;
357+
for r in &results {
358+
println!("ID: {}, distance: {}", r.id, r.distance);
359+
}
334360
```
335361

362+
**Use cases:** Semantic caching, large-scale deduplication, insert-heavy workloads (~1us insert vs ~2ms for HNSW).
363+
336364
---
337365

338366
## Rust Usage

0 commit comments

Comments
 (0)