SearchEngine— fuzzy text search via Fuse.js. No server required, runs entirely in-memory.SemanticSearchEngine— vector similarity search using pre-computed embeddings.
@understand-anything/core/search subpath (browser-safe) and from the main @understand-anything/core entry.
SearchEngine
Fuzzy full-text search over a collection ofGraphNode objects.
Constructor
Initial set of graph nodes to index. The Fuse.js index is built immediately on construction.
search()
query is blank or whitespace-only.
How it works:
- The query is trimmed.
- Space-separated tokens are joined with
|(logical OR) to produce a Fuse.js extended search expression — e.g."auth contrl"becomes"auth | contrl". This means a node matches if it contains any of the tokens, making the search tolerant of typos across separate words. - Results are filtered by
options.typesif provided, then sliced tooptions.limit.
Search query string. Multi-word queries match nodes that contain any of the words (OR semantics).
Optional search configuration.
SearchResult[]
The
id of the matching GraphNode.Fuse.js match score.
0 is a perfect match, 1 is the worst possible match. Results are returned in ascending score order (best first).updateNodes()
New complete set of nodes to index.
Fuse.js Configuration
The Fuse.js instance is configured with the following options, applied consistently across allSearchEngine instances:
| Option | Value | Effect | |
|---|---|---|---|
threshold | 0.4 | Controls fuzziness. Lower = stricter. 0.4 allows moderate typos. | |
ignoreLocation | true | Matches anywhere in the string, not just near the start. | |
useExtendedSearch | true | Enables the ` | ` OR operator in query strings. |
includeScore | true | Populates score on each result. |
| Field | Weight | Rationale |
|---|---|---|
name | 0.4 | Symbol names are the most direct match signal |
tags | 0.3 | Keyword tags boost topical relevance |
summary | 0.2 | Prose description provides broader coverage |
languageNotes | 0.1 | Language idiom notes contribute marginally |
SearchResult
SearchEngine.search() and SemanticSearchEngine.search().
SearchOptions
SearchEngine.search().
Usage example
SemanticSearchEngine
Vector similarity search using pre-computed embeddings. ComplementsSearchEngine when embedding data is available.
Constructor
The graph nodes to search over.
Pre-computed embedding vectors keyed by
GraphNode.id. Nodes without a corresponding embedding are skipped during search.search()
score order (best first), where score = 1 - cosineSimilarity so that 0 still means a perfect match, consistent with SearchResult.
Embedding vector for the query, produced by the same model used to embed the nodes.
Optional search configuration.
SearchResult[] — same shape as SearchEngine.search().
hasEmbeddings()
true if any embeddings have been stored. Use this to decide whether to fall back to fuzzy search.
addEmbedding()
The
GraphNode.id to associate the embedding with.The embedding vector.
updateNodes()
New complete set of nodes.
cosineSimilarity()
Utility function exported alongside the search engines.0 if either vector has zero magnitude.