corpus

package
v2.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 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 corpus provides a reference memory.Retriever over a fixed set of documents: a knowledge base the host supplies, separate from the memory.Store the memory tools read and write.

The two retrieval paths in PromptKit answer different questions:

  • The memory tools (memory__remember / memory__recall) let the model manage facts about the *subject*: what the user told it to remember. The model decides when to look, and the store is scoped per subject.
  • Ambient injection asks a corpus what is relevant to *this turn* and puts the answer in the system prompt before the model runs. The model never decides; it sees grounding it did not have to ask for.

Pointing ambient injection at the memory store would collapse the two into one path, and the model would find the same rows twice, once by asking and once without. Retrieval for grounding belongs over the host's own content: documentation, a product catalog, a support knowledge base.

This implementation scores documents by term overlap with the latest user turn. That is enough to develop and test against, and is not a search engine: production hosts implement memory.Retriever against a vector index or a real search backend.

Index

Constants

View Source
const (
	// MemoryType is the [memory.Memory] Type given to every retrieved
	// document, so a context formatter (or a host reading the injected set)
	// can tell grounding documents apart from remembered facts.
	MemoryType = "document"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// ID identifies the document; it is carried onto the retrieved
	// memory so a prompt can cite it.
	ID string
	// Title is a human-readable label, surfaced in metadata.
	Title string
	// Text is the content injected into the prompt.
	Text string
}

Document is one unit of retrievable host content.

type Option

type Option func(*Retriever)

Option configures a Retriever.

func WithTopK

func WithTopK(n int) Option

WithTopK caps how many documents are injected. It defaults to 3. A value of zero or less injects every matching document.

type Retriever

type Retriever struct {
	// contains filtered or unexported fields
}

Retriever answers ambient-injection queries from a fixed document set.

func New

func New(docs []Document, opts ...Option) *Retriever

New returns a Retriever over docs.

func (*Retriever) RetrieveContext

func (r *Retriever) RetrieveContext(
	_ context.Context, _ map[string]string, messages []types.Message,
) ([]*memory.Memory, error)

RetrieveContext implements memory.Retriever. The query is the latest user turn, the one the assistant is about to answer. Documents are ranked by the number of terms they share with it, with declaration order breaking ties.

A turn with no user text, or one sharing no term with any document, returns nothing.

Jump to

Keyboard shortcuts

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