service

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 Document

type Document struct {
	Locator, Revision string
	ModifiedMs        uint64
	Tags              []string
	Embedded          bool
}

Document identifies one indexed source and what its chunks were built from.

type Embedding

type Embedding struct {
	Model    string
	Identity string
	Values   []float32
}

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

func (index Index) Bind(ctx context.Context, binding Binding) error

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) Counts

func (index Index) Counts(ctx context.Context, binding Binding) (sources, chunks uint64, err error)

Counts returns the sources and chunks published for this binding.

func (Index) Prune

func (index Index) Prune(ctx context.Context, binding Binding, locators, kept []string) error

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.

func (Index) Retain

func (index Index) Retain(ctx context.Context, ids []protocol.KnowledgeID) error

Retain drops the collections that no longer exist.

func (Index) Search

func (index Index) Search(ctx context.Context, query protocol.KnowledgeQuery, allowed []Binding, embeddings []Embedding, indexing bool) (protocol.KnowledgePage, error)

Search ranks the chunks the bindings admit and returns one page.

func (Index) Unchanged

func (index Index) Unchanged(ctx context.Context, binding Binding, document Document) (found bool, err error)

Unchanged reports a source already published for this binding.

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 New

func New(options Options) *Service

New prepares a service; Start runs its worker.

func (*Service) Citation

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.

func (*Service) Start

func (service *Service) Start()

Start runs the indexing worker and requests the first pass.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL