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 ¶
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 Retriever ¶
type Retriever struct {
// contains filtered or unexported fields
}
Retriever answers ambient-injection queries from a fixed document set.
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.