feat(retrieval): Phase 1 — typed schema and FT.CREATE translation#236
feat(retrieval): Phase 1 — typed schema and FT.CREATE translation#236jamby77 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0b682d2. Configure here.
3c8b814 to
6ce7dde
Compare
0b682d2 to
c14395b
Compare
…nslation - Add RetrievalSchema, FieldSpec, VectorSpec, FtCapabilities types in schema.ts - Implement pure buildFtCreateArgs in ft-create.ts: HNSW (6 pairs/12 params with defaults M=16 EF_CONSTRUCTION=200 EF_RUNTIME=10), FLAT (3 pairs/6 params), all three field types (text/tag/separator/numeric/sortable), metric mapping, textFields capability gate, dims/fieldName/algorithm-param validation - 24 table-driven tests, TDD red→green - Export all public types + builder from index.ts - Remove --passWithNoTests from test script
- Discriminated-union VectorSpec: HnswVectorSpec / FlatVectorSpec split so FLAT cannot carry HNSW params at the type level - Replace validateDims void + as-cast with requireDims narrowing guard - Add indexName/keyPrefix helpers with empty-name validation; export both - resolveVectorFieldName helper eliminates duplicated ?? 'embedding' - validateFlatHnswParams uses 'in' guards, accepts VectorSpec (no any) - METRIC_MAP typed as Record<VectorMetric, string> - Harmonize error messages to include offending value - Replace no-interpolation template literals with single-quoted strings - Prettier pass over all src files - 32 tests (up from 24): FLAT dims missing/invalid, empty/whitespace index name, indexName/keyPrefix unit cases; FLAT+HNSW param throw tests construct invalid objects via property mutation to avoid casts in production code
…sIndexNotFoundError
c14395b to
93458ff
Compare
|
Minor DX note: fresh-checkout tests fail until the kit is built Running Vitest resolves the workspace symlink through the kit's Totally fine to leave as-is if this is already planned for one of the next PRs in the stack — just flagging it so it doesn't get lost. |

Summary
Phase 1 of the Retrieval SDK plan, stacked on #234 (Phase 0). Adds the first code of
@betterdb/retrievalplus one deferred Phase 0 review item in the kit.packages/retrieval(@betterdb/retrieval0.1.0), mirroringvalkey-search-kit, with a workspace dep on the kitbuildFtCreateArgs(name, schema, capabilities?)translating the typed index schema (text / tag+separator / numeric+sortable fields; HNSW|FLAT vector as a discriminated union) into the full FT.CREATE argument vector — HNSW defaults M=16 / EF_CONSTRUCTION=200 / EF_RUNTIME=10 always emitted; exportedindexName()/keyPrefix()naming helpersFtCapabilities.textFields— valkey-search < 1.2 rejectsTEXT, so callers on older modules get an actionable error instead of a server failureisIndexNotFoundErrorinvalkey-search-kit: the broad'not found'substring match is now scoped to index errors ('not found'+'index'co-occurrence). Verified against live engines — valkey-search 1.2 emitsIndex with name '…' not found in database 0, Redis 8 emitsNo such index …; both stay matched, generickey not found-style messages no longer misclassify. The semantic-cache characterization lock was deliberately split into positive + negative cases for this.Test Plan
@betterdb/retrievalunit tests: 32/32 (table-driven, full-vector deep equality)@betterdb/valkey-search-kitunit tests: 32/32 (incl. empirically captured engine phrasings)@betterdb/semantic-cachesuite: 191/191 (characterization net intact)tscbuilds clean across the three packagesNote
Medium Risk
The stricter
isIndexNotFoundErrorheuristic changes runtime behavior for semantic-cache index bootstrap across engine error phrasings; mis-tuned matching could skip auto-create or surface errors instead of recovering.Overview
Introduces
@betterdb/retrieval(Phase 1) as a new workspace package with typed index schema (text/tag/numericfields plus HNSW or FLAT vector specs) and a purebuildFtCreateArgstranslator that emits the fullFT.CREATEargument vector, including default HNSW tuning andindexName/keyPrefixhelpers.FtCapabilities.textFieldsblocks TEXT emission on valkey-search < 1.2 with a clear error instead of a server failure.In
valkey-search-kit,isIndexNotFoundErrorno longer treats every"not found"substring as a missing index—it now requires index-related wording alongside"not found", so messages likekey not foundare not misclassified. semantic-cache characterization tests are updated to lock in that positive vs negative behavior.Reviewed by Cursor Bugbot for commit 93458ff. Bugbot is set up for automated code reviews on this repo. Configure here.