knowledge_store library

Saved local indexes of OKF bundles and dense search over them, for a host that embeds what wayfinder index and wayfinder search do.

A WayfinderKnowledgeStore indexes and searches the bundles of a package:wayfinder/project.dart project, which the host discovers from the project root it opens, so nothing above that root is read. The host owns the resources: it supplies the data directory and a WayfinderEncoderProvider, such as a LocalModelEncoderProvider over a model file it located. The store never downloads, prompts, or loads native code or a model on its own (ADR-0018), and needs no database library: each index is a sequence of immutable generation files that searches read without a lock while an index runs. Keep all okf bundle I/O of a process, this store's included, on one isolate.

import 'dart:io';

import 'package:wayfinder/project.dart';
import 'package:wayfinder_embeddings/knowledge_store.dart';

// The root of the workspace the host opens; discovery reads nothing
// above it.
final project = await WayfinderProject.discover(Directory('/work/app'));
final store = WayfinderKnowledgeStore(
  dataDirectory: WayfinderDataDirectory.resolve(),
  encoder: LocalModelEncoderProvider(modelFile: File('embedding.gguf')),
);
try {
  for (final bundle in project.bundles) {
    await store.index(bundle);
  }
  final result = await store.search(project.bundles, 'password reset');
  print(result.toMarkdown());
} finally {
  await store.dispose();
}

package:wayfinder_embeddings/testing.dart has a deterministic encoder for tests.

Classes

BaseEmbedder
Base interface for all content embedders.
Chunk
Base class for all content chunks.
EmbeddingModelSpec
Pinned artifact and preprocessing contract for a local embedding model.
IndexProgress
An event WayfinderKnowledgeStore.index reports while it runs. A current index reports only IndexPhase.scanning.
KnowledgeBundleSearch
A search of one bundle, with its context unranked against other bundles.
KnowledgeCitation
One cited passage of a search: a match, or context reached from one.
KnowledgeContextHit
A cited passage selected as a match, governing source, or related context.
KnowledgeIndexCurrent
The saved index matches the bundle; indexing has nothing to do and search can use it.
KnowledgeIndexIncompatible
The saved index cannot be used and indexing replaces it.
KnowledgeIndexMissing
No index was saved for this configuration and encoder.
KnowledgeIndexRefreshing
An operation is indexing the bundle, or forgetting its index, right now. Searches still read the last published generation, which previous describes; with StaleIndexPolicy.serveWhileRefreshing they serve it even when it is stale.
KnowledgeIndexStale
The bundle changed since it was indexed; search refuses the index until it is indexed again.
KnowledgeIndexStatus
The state of a bundle's saved index for the store's configuration and encoder, from WayfinderKnowledgeStore.status.
KnowledgeInputDiagnostic
A successful embedding-input recovery, aggregated by source and code.
KnowledgeMetadataFilter
Deterministic frontmatter eligibility, independent of retrieval scores. Values within each set use OR, except requiredTags, which uses AND. Different fields combine with AND. Identifiers are exact and case-sensitive; title/description containment is literal and case-insensitive.
KnowledgeNotice
Something a search reports besides its passages: a stable code, the sentence message, and the paths it concerns.
KnowledgeProjectSearch
A search across a project's bundles, ranked together under one limit.
KnowledgePrunedIndex
One index directory WayfinderKnowledgeStore.prune removed.
KnowledgePruneResult
What WayfinderKnowledgeStore.prune removed and what it left in use.
KnowledgeSearchFreshness
What a search found out about one bundle's index besides its passages.
KnowledgeSearchResponse
LocalModelEncoderProvider
A local GGUF model file the host located, opened with LlamaEmbedder.
SearchResult
Represents a search result.
WayfinderEncoder
An open encoder: its embedder, the tokenizer that counts an input's tokens, and the most tokens one input may have.
WayfinderEncoderProvider
Where a WayfinderKnowledgeStore gets its encoder.
WayfinderIndexResult
Counts and location of a completed local indexing operation.
WayfinderKnowledgeStore
Saved local indexes of OKF bundles, and dense search over them.

Enums

EmbeddingModelRemedy
What fixes a model EmbeddingModelSpec.verify refuses, as data for a host to word: the library's messages name no command (ADR-0018).
IndexPhase
A step of WayfinderKnowledgeStore.index.
KnowledgeNoticeCode
What a KnowledgeNotice reports. wireValue is the stable code a host matches; a later release may add codes, so a switch over them keeps a default.
StaleIndexPolicy
What a search does with a saved index that no longer matches its bundle.

Constants

localEmbeddingModel → const EmbeddingModelSpec
Arctic Embed XS Q8_0, using CLS pooling and normalized retrieval vectors.
wayfinderLlamaCppRuntime → const String
The leehack/llamadart-native release whose llama.cpp build Wayfinder reviewed and measured its vectors with: what its notices attribute and what the knowledge store's configuration names.

Properties

knowledgeMetadataFilterInput → ObjectSchema
The frontmatter filters a host tool accepts, as JSON, with the meaning of KnowledgeMetadataFilter: optional tags, require_tags, types, statuses and path_prefixes lists, and title_contains and description_contains strings. Convert a parsed value with knowledgeMetadataFilterFromInput.
final
wayfinderSearchInput → ObjectSchema
The search a host tool accepts, as JSON: a query with a non-blank character and an optional limit from 1 to 100 (default 5). The CLI converts its arguments to numbers before parsing them with it.
final

Functions

knowledgeMetadataFilterFromInput(Map<String, Object?> input) → KnowledgeMetadataFilter
The KnowledgeMetadataFilter a value knowledgeMetadataFilterInput parsed describes; absent keys filter nothing.

Typedefs

WayfinderEncoderIdentity = ({String model, String source})
The identity of an encoder: the BaseEmbedder.modelName and BaseEmbedder.sourceName it reports.

Exceptions / Errors

EmbeddingModelMismatchException
EmbeddingModelSpec.verify found a model file at path whose size or SHA-256 is not the pinned model's. It is a FormatException, so code that catches one still does.
EmbeddingModelMissingException
EmbeddingModelSpec.verify found no model file at path. It is a FileSystemException, so code that catches one still does.