@delali/narsil 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -196,6 +196,7 @@ await narsil.createIndex('articles', {
196
196
  | `stopWords` | `Set<string> \| (defaults: Set<string>) => Set<string>` | Replaces or transforms the language module's stop word set. |
197
197
  | `tokenizer` | `CustomTokenizer` | Replaces the built-in tokenizer with your own `tokenize(text)` implementation. |
198
198
  | `trackPositions` | `boolean` | Stores token positions for highlighting. The default is `true`. |
199
+ | `surfaceForms` | `boolean` | Records the original spellings of stemmed words for suggestions and prefix completions. The default is `false`. See [Suggestions](#suggestions). |
199
200
  | `vectorPromotion` | `VectorIndexConfig` | Tunes the HNSW promotion threshold, graph parameters, and quantization. See [Vector search](#vector-search). |
200
201
  | `strict` | `boolean` | Rejects documents that carry fields missing from the schema. |
201
202
  | `embedding` | `EmbeddingFieldConfig` | Maps text fields to vector fields for auto-embedding. See [Embedding adapters](#embedding-adapters). |
@@ -314,6 +315,19 @@ const results = await narsil.query('products', {
314
315
  })
315
316
  ```
316
317
 
318
+ ### Search as you type
319
+
320
+ `prefix: true` treats the last word of the query as an unfinished word, so `secur` matches documents containing `security`. Earlier words must match fully, and `tolerance` keeps applying to them while the unfinished word is completed instead of typo-corrected. Completions score against a shared document frequency and rank below full-word matches, so a document containing the exact typed word comes first. The option is off by default; turn it on for queries fired on every keystroke.
321
+
322
+ Completions match against the term dictionary, which stores stemmed tokens, so a typed word that runs past the end of a stem stops matching: `security` is indexed as `secur`, and the query `securi` finds nothing. Create the index with `surfaceForms: true` to match completions against the original spellings instead; the same setting gives [suggestions](#suggestions) their display words.
323
+
324
+ ```ts
325
+ const results = await narsil.query('products', {
326
+ term: 'mechanical keyb',
327
+ prefix: true,
328
+ })
329
+ ```
330
+
317
331
  ### Score and coverage thresholds
318
332
 
319
333
  `minScore` drops hits scoring below a floor. `termMatch` sets how many query terms a document must match: `'any'` (the default) accepts one term, `'all'` requires every term, and a number requires at least that many terms.
@@ -476,11 +490,16 @@ const { count, elapsed } = await narsil.preflight('products', { term: 'keyboard'
476
490
 
477
491
  ### Suggestions
478
492
 
479
- `suggest(indexName, params)` returns autocomplete candidates from the index's term dictionary. It tokenizes the input, takes the last word as the prefix, and ranks matching terms by document frequency.
493
+ `suggest(indexName, params)` returns autocomplete candidates. It tokenizes the input, takes the last word as the prefix, and ranks completions by the number of documents they match. By default the candidates are the stemmed tokens the index stores, so a catalogue containing "mechanical" suggests the stem `mechan`. Create the index with `surfaceForms: true` to suggest the words as they appear in your documents; the engine then records the original spelling of every word the stemmer changed and suggests `mechanical` instead.
480
494
 
481
495
  ```ts
496
+ await narsil.createIndex('products', {
497
+ schema: { title: 'string', description: 'string' },
498
+ surfaceForms: true,
499
+ })
500
+
482
501
  const suggestions = await narsil.suggest('products', { prefix: 'mech', limit: 5 })
483
- // suggestions.terms => [{ term: 'mechan', documentFrequency: 12 }, ...]
502
+ // suggestions.terms => [{ term: 'mechanical', documentFrequency: 12 }, ...]
484
503
  ```
485
504
 
486
505
  ## Vector search