Documentation
¶
Overview ¶
Package service indexes knowledge collections and answers queries and citation reads. Its retrieval data is rebuildable; source registrations and grants stay in the Node database.
Index ¶
- type Binding
- type Document
- type Embedding
- type Index
- func (index Index) Bind(ctx context.Context, binding Binding) error
- func (index Index) Cached(ctx context.Context, binding Binding, locator string, stat source.Stat, ...) (found bool, err error)
- func (index Index) Candidates(ctx context.Context, query protocol.KnowledgeQuery, allowed []Binding, ...) ([]protocol.KnowledgeHit, error)
- func (index Index) Counts(ctx context.Context, binding Binding) (sources, chunks uint64, err error)
- func (index Index) Prune(ctx context.Context, binding Binding, locators, kept []string) error
- func (index Index) Remember(ctx context.Context, binding Binding, locator string, stat source.Stat) error
- func (index Index) Replace(ctx context.Context, binding Binding, document Document, parts []Part) error
- func (index Index) Retain(ctx context.Context, ids []protocol.KnowledgeID) error
- func (index Index) Search(ctx context.Context, query protocol.KnowledgeQuery, allowed []Binding, ...) (protocol.KnowledgePage, error)
- func (index Index) Unchanged(ctx context.Context, binding Binding, document Document) (found bool, err error)
- type Options
- type Part
- type Service
- func (service *Service) Citation(ctx context.Context, request protocol.Request, ...) (protocol.KnowledgeCitationPage, error)
- func (service *Service) Close()
- func (service *Service) Invalidate()
- func (service *Service) Query(ctx context.Context, request protocol.Request, query protocol.KnowledgeQuery) (protocol.KnowledgePage, error)
- func (service *Service) Refresh()
- func (service *Service) SearchStorage(ctx context.Context, request protocol.Request) (protocol.PluginStorageSearchPage, error)
- func (service *Service) Start()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
type Binding struct {
ID protocol.KnowledgeID
Generation uint64
Model string
Identity string
Dimension int
Scope [32]byte
Rebuild uint64
Paused bool
}
Binding captures what the chunks of a collection are valid for. An empty Model is keyword only. Identity is the content identity of the model's definition: vectors are kept and compared only under the same model and identity, so a model whose files changed under its name starts over.
type Embedding ¶
Embedding is one model's vector of the query text. It is compared only with vectors built by the same model and identity (Binding).
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is the derived retrieval data of every collection. It keeps the vectors of queried collections in memory between writes.
func (Index) Bind ¶
Bind records what a collection is indexed for. A changed source capture or rebuild drops its sources; a changed model only drops their vectors.
func (Index) Cached ¶
func (index Index) Cached(ctx context.Context, binding Binding, locator string, stat source.Stat, tags []string, embedded bool) (found bool, err error)
Cached reports a file whose metadata witness matches its published source. Ordinary writers are witnessed by size and time; citation reads still hash the content.
func (Index) Candidates ¶
func (index Index) Candidates(ctx context.Context, query protocol.KnowledgeQuery, allowed []Binding, embeddings []Embedding, alternatives []string) ([]protocol.KnowledgeHit, error)
Candidates returns the nearest chunks of a query by meaning alone, for a caller that fuses them with its own keyword ranking. A source needs every query tag and, when any are given, one of the alternatives. Without a usable vector there are none.
func (Index) Prune ¶
Prune drops the sources a scan no longer found. Sources below a kept prefix stay: the scan could not enter their directory.
func (Index) Remember ¶
func (index Index) Remember(ctx context.Context, binding Binding, locator string, stat source.Stat) error
Remember keeps the metadata witness of a published file.
func (Index) Replace ¶
func (index Index) Replace(ctx context.Context, binding Binding, document Document, parts []Part) error
Replace publishes one verified source atomically.
type Options ¶
type Options struct {
Node protocol.NodeID
// Index is the knowledge database of the profile.
Index *store.Handle
// Context restores the stored source principal for one background collection.
Context func(context.Context, store.KnowledgeStored) (context.Context, error)
// Catalog lists every registered collection.
Catalog func(ctx context.Context) ([]store.KnowledgeStored, error)
// Allowed lists the collections a request may read.
Allowed func(ctx context.Context, request protocol.Request) ([]store.KnowledgeStored, error)
// Progress records and publishes the progress of one collection.
Progress func(ctx context.Context, id protocol.KnowledgeID, generation uint64, progress protocol.KnowledgeProgress) error
// Root resolves the current directory of a captured worktree.
Root func(ctx context.Context, worktree protocol.WorktreeID) (string, error)
// Choice is the saved embedding selection.
Choice func() protocol.ModelsLocalChoice
// Dimension is the vector size of a registered embedding model and the
// content identity of its definition.
Dimension func(model string) (dimension int, identity string, found bool)
// Installed lists the embedding models that can run.
Installed func() (map[string]bool, error)
// Encode embeds at most four texts. Query texts run ahead of background
// document work.
Encode func(ctx context.Context, model string, choice protocol.ModelsLocalChoice, texts []string, query bool) ([][]float32, error)
// Offsets returns the byte range of every model token of a text.
Offsets func(ctx context.Context, model string, choice protocol.ModelsLocalChoice, text string) ([][2]int, error)
// Sources reads the next page of the plugin values a storage collection
// indexes; after continues a scan.
Sources func(ctx context.Context, stored store.KnowledgeStored, after *string) (store.KnowledgeStoragePage, error)
// Source captures one plugin value of a storage collection, or nil.
Source func(ctx context.Context, stored store.KnowledgeStored, key string) (*store.KnowledgeStorageRecord, error)
// SourceCurrent reports whether a captured plugin value is unchanged.
SourceCurrent func(ctx context.Context, stored store.KnowledgeStored, record store.KnowledgeStorageRecord) (bool, error)
// Plan captures what one plugin storage search may rank.
Plan func(ctx context.Context, request protocol.Request) (store.SemanticPlan, error)
// Materialize reads the values a plugin storage search selected and
// reports a selection that went stale.
Materialize func(ctx context.Context, request protocol.Request, plan store.SemanticPlan, selection store.SemanticSelection) (protocol.PluginStorageSearchPage, bool, error)
// OCR reads images and scanned PDF pages.
OCR *source.OCR
Clock clockwork.Clock
// Working, when set, brackets a collection from its first changed source
// to the end of its pass.
Working func() func()
}
Options connects the service to the Node that owns it.
type Part ¶
type Part struct {
Title, Text string
Position protocol.KnowledgePosition
Vector *knowledge.Vector
}
Part is one chunk to publish.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the retrieval index and the worker that maintains it.
func (*Service) Citation ¶
func (service *Service) Citation(ctx context.Context, request protocol.Request, input protocol.KnowledgeCitationRequest) (protocol.KnowledgeCitationPage, error)
Citation rereads a cited source through the current grants. A citation whose collection, source or chunk changed is reported and reindexed.
func (*Service) Close ¶
func (service *Service) Close()
Close cancels indexing and waits for a started worker.
func (*Service) Invalidate ¶
func (service *Service) Invalidate()
Invalidate cancels the running pass and asks for another one that tries every failed source again.
func (*Service) Query ¶
func (service *Service) Query(ctx context.Context, request protocol.Request, query protocol.KnowledgeQuery) (protocol.KnowledgePage, error)
Query answers a search with the collections the request may read.
func (*Service) Refresh ¶
func (service *Service) Refresh()
Refresh asks the worker for another pass.
func (*Service) SearchStorage ¶
func (service *Service) SearchStorage(ctx context.Context, request protocol.Request) (protocol.PluginStorageSearchPage, error)
SearchStorage answers a plugin's search of its own values. Meaning is ranked by the automatic collections of the package and fused with the keyword ranking; every returned value is read as it is now.