Class RedbKnowledgeStore
REDB-backed . One row per chunk; every chunk
field is stored on the indexed base columns and
the scheme is intentionally
property-less — chunks read / write a single _objects row
with zero _props rows. Column layout:
value_string — stable chunk id (business key; partial index on
PostgreSQL/SQLite, no index on MSSQL — NVARCHAR(MAX)). New rows also
carry it, normalized, in _value_unique: the per-scheme unique
index keeps concurrent upserts of one id on a single row.name — collection / namespace.note — JSON envelope {"text":"...","meta":"..."}.value_bytes — embedding, written as the raw byte view of
the float[] via .value_long — embedding dimensionality (sanity check).
Search strategy: the MVP loads candidate chunks (filtered by
collection) and computes cosine similarity in process. Acceptable up to a
few thousand chunks. For production scale plug in a pgvector / Qdrant
adapter that overrides only .
The store does not own an instance — each call
resolves one through IRouteContext.GetRedbService(name, exchange),
which honours the per-exchange scope cache. The redb name is read from
exchange.Properties[LlmKeys.RedbName] (set by the LLM endpoint URI),
falling back to the constructor-supplied default name and then to the host's
default unnamed instance.
public sealed class RedbKnowledgeStore : IKnowledgeStore
Inheritance
Implements
Methods
DeleteAsync(string, IExchange?, CancellationToken)
Drops a chunk by id; no-op when not found.
public Task DeleteAsync(string chunkId, IExchange? exchange = null, CancellationToken ct = default)
SearchAsync(ReadOnlyMemory<float>, int, string?, IExchange?, CancellationToken)
Returns the topK most-similar chunks for the query embedding.
public Task<IReadOnlyList<KnowledgeSearchResult>> SearchAsync(ReadOnlyMemory<float> queryEmbedding, int topK, string? collection = null, IExchange? exchange = null, CancellationToken ct = default)
SearchTextAsync(string, int, string?, IExchange?, CancellationToken)
Keyword fallback — returns up to topK chunks whose text
public Task<IReadOnlyList<KnowledgeSearchResult>> SearchTextAsync(string query, int topK, string? collection = null, IExchange? exchange = null, CancellationToken ct = default)
UpsertAsync(KnowledgeChunk, IExchange?, CancellationToken)
Persists or replaces a chunk by its .
public Task UpsertAsync(KnowledgeChunk chunk, IExchange? exchange = null, CancellationToken ct = default)
UpsertManyAsync(IEnumerable<KnowledgeChunk>, IExchange?, CancellationToken)
Persists or replaces many chunks at once. Bulk-friendly stores commit
public Task UpsertManyAsync(IEnumerable<KnowledgeChunk> chunks, IExchange? exchange = null, CancellationToken ct = default)
Constructors
RedbKnowledgeStore(IRouteContext, string?)
Creates the store. Scheme is synced by the host's redb.InitializeAsync().