Skip to content

Commit d53cfd2

Browse files
committed
chore: benchmarking
1 parent 9a17c71 commit d53cfd2

7 files changed

Lines changed: 1119 additions & 74 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ dist
99
.output
1010
coverage
1111
.retriv
12+
bench-results.json
13+
.retriv-bench.db

README.md

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Most search tools force you to choose: keyword search (fast, exact matches) or v
3636

3737
## Features
3838

39-
- 🎯 **Hybrid search + reranking** — AND keywords + OR keywords + vector semantic, merged via weighted [RRF](https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf), with optional cross-encoder reranking and per-category fusion
40-
- 📦 **Local to cloud** — start with a single SQLite file, scale to cloud providers for vectors, embeddings, and reranking
39+
- 🎯 **Hybrid search** — AND keywords + OR keywords + vector semantic, merged via weighted [RRF](https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf), with per-category fusion
40+
- 📦 **Local to cloud** — start with a single SQLite file, scale to cloud providers for vectors and embeddings
4141
- 🌳 **AST-aware code chunking** — powered by [`code-chunk`](https://github.com/supermemoryai/code-chunk), uses [tree-sitter](https://tree-sitter.github.io/) to split on function/class boundaries with entity, scope, and import metadata
4242
- 🔍 **Search filtering** — narrow results by file type, path prefix, or any custom field
4343
- 🔌 **Swappable backends** — SQLite, LibSQL/Turso, pgvector, Upstash, Cloudflare Vectorize
@@ -66,15 +66,13 @@ import { createRetriv } from 'retriv'
6666
import { autoChunker } from 'retriv/chunkers/auto'
6767
import sqlite from 'retriv/db/sqlite'
6868
import { transformersJs } from 'retriv/embeddings/transformers-js'
69-
import { crossEncoder } from 'retriv/rerankers/transformers-js'
7069

7170
const search = await createRetriv({
7271
driver: sqlite({
7372
path: './search.db',
7473
embeddings: transformersJs(),
7574
}),
7675
chunking: autoChunker(), // code + markdown-aware splitting
77-
rerank: await crossEncoder(), // cross-encoder reranking for better precision
7876
})
7977
```
8078

@@ -116,34 +114,6 @@ await search.search('getUserName', { filter: { type: 'code' } })
116114
// ]
117115
```
118116

119-
### Reranking
120-
121-
Add a cross-encoder reranking pass after fusion. The reranker re-scores candidates using query-document attention, improving precision on top results:
122-
123-
```ts
124-
import { crossEncoder } from 'retriv/rerankers/transformers-js'
125-
126-
const search = await createRetriv({
127-
driver: sqlite({
128-
path: './search.db',
129-
embeddings: transformersJs(),
130-
}),
131-
rerank: await crossEncoder(), // local cross-encoder, no API key
132-
})
133-
```
134-
135-
The reranker automatically over-fetches 3x candidates, re-scores them, then trims to your requested `limit`. Results without content are passed through unchanged.
136-
137-
You can also pass any function matching `(query: string, results: SearchResult[]) => Promise<SearchResult[]>`:
138-
139-
```ts
140-
// Custom reranker (e.g. Cohere rerank API)
141-
rerank: async (query, results) => {
142-
const reranked = await cohereRerank(query, results)
143-
return reranked
144-
}
145-
```
146-
147117
### Split-Category Search
148118

149119
When one category of documents (e.g. prose docs) outnumbers another (e.g. code definitions), the majority can drown out minority results. Split-category search fixes this by running parallel filtered searches per category and fusing with RRF — each category gets equal representation regardless of volume.
@@ -176,8 +146,6 @@ categories: doc => /\.(?:ts|js)$/.test(doc.id) ? 'code' : 'docs'
176146
categories: doc => doc.metadata?.category
177147
```
178148

179-
Works with reranking — the reranker runs on the fused result set after category merging.
180-
181149
### Cloud Embeddings
182150

183151
```bash
@@ -463,18 +431,6 @@ interface ChunkerChunk {
463431
}
464432
```
465433

466-
## Rerankers
467-
468-
| Reranker | Import | Peer Dependencies |
469-
|----------|--------|-------------------|
470-
| Cross-encoder | `retriv/rerankers/transformers-js` | `@huggingface/transformers` |
471-
472-
```ts
473-
// Local cross-encoder (default: Xenova/ms-marco-MiniLM-L-6-v2)
474-
await crossEncoder()
475-
await crossEncoder({ model: 'Xenova/ms-marco-MiniLM-L-6-v2' })
476-
```
477-
478434
## Related
479435

480436
- [skilld](https://github.com/harlan-zw/skilld) — Generate agent skills from npm package docs, uses retriv for search

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"code-chunk": "catalog:",
194194
"eslint": "catalog:",
195195
"obuild": "catalog:",
196+
"osgrep": "^0.5.16",
196197
"pg": "catalog:",
197198
"sqlite-vec": "catalog:",
198199
"typescript": "catalog:",

0 commit comments

Comments
 (0)