Home

giogio / openez-graph

public
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

fix(retrieval): correct sqlite-vec KNN query syntax for ANN search

3 months ago

bcebc30
Authored
asta-nguyen8/8/2026, 7:00:15 AM
The ANN query put MATCH in ORDER BY instead of WHERE and didn't use
the hidden distance column for ordering. Per sqlite-vec docs, the
correct KNN pattern is:

  WHERE embedding MATCH ? AND <metadata filters>
  ORDER BY distance
  LIMIT k

The old query would error out when the vec extension is loaded,
silently falling back to linear scan — defeating the ANN optimization.
Under bun:sqlite the extension never loads so the bug was latent, but
it would manifest on any SQLite build with extension loading support.

Typecheck 8/8, tests 144 pass.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Parent7261302

1 file changed
  • packages/core/src/retrieval.ts+4−3