Documentation
¶
Overview ¶
Package knowledge defines golem's portable knowledge-base facade.
The facade deliberately uses Eino's schema.Document and retriever.Retriever types. A vector database, an embedding model, and document extraction are implementation details of an optional module; the agent only needs scoped indexing, enumeration, deletion, moving, and search.
Index ¶
- Constants
- func ContextText(documents []*schema.Document, maxChars int) string
- func DocumentOwnedBy(scope Scope, docID string) func(Metadata) bool
- func DocumentReadableBy(scope Scope, docID string) func(Metadata) bool
- func FirstChunk(metadata Metadata) bool
- func MetadataFor(scope Scope, docID, title, source string, createdAt time.Time, ...) map[string]any
- func NewRetriever(base KnowledgeBase, scope Scope, topK int, filter func(Metadata) bool) retriever.Retriever
- func ReadableBy(scope Scope) func(Metadata) bool
- func ScopeForMetadata(values map[string]any) (Scope, Target)
- func WritableBy(scope Scope) func(Metadata) bool
- type AdminTools
- type Entry
- type FilteredKnowledgeBase
- type KnowledgeBase
- type KnowledgeRetrieval
- type Metadata
- type Page
- type RetrievalConfig
- type Scope
- type ScopedRetriever
- type Source
- type Target
- type Tools
- type ToolsOption
Constants ¶
const ( MetadataOwner = "golem.owner" MetadataGroup = "golem.group" MetadataTenant = "golem.tenant" MetadataDocID = "golem.doc_id" MetadataTitle = "golem.title" MetadataSource = "golem.source" MetadataCreatedAt = "golem.created_at" MetadataChunk = "golem.chunk" MetadataChunkCount = "golem.chunk_count" )
Metadata keys are stable across Eino vector-store implementations.
const ( ToolNameListKnowledge = "ListKnowledgeBase" ToolNameIndexKnowledge = "IndexKnowledge" ToolNameSearchKnowledge = "SearchKnowledge" ToolNameMoveKnowledge = "UpdateKnowledgeScope" ToolNameDeleteKnowledge = "DeleteKnowledge" ToolNameListOwnerKnowledge = "ListOwnerKnowledgeBase" ToolNameSearchOwnerKnowledge = "SearchOwnerKnowledge" )
Variables ¶
This section is empty.
Functions ¶
func ContextText ¶
ContextText renders retrieved passages as clearly delimited reference material. Content is data supplied by a knowledge author, not an instruction, so the boundary is part of the facade rather than left to every model integration.
func DocumentOwnedBy ¶
DocumentOwnedBy returns the exact write-replacement predicate. All three fields, including blanks, must match; using ReadableBy here could replace a shared document when a caller merely has read access to it.
func DocumentReadableBy ¶
DocumentReadableBy returns the read predicate for one document id.
func FirstChunk ¶
FirstChunk returns whether a chunk is the document representative used for document-level listing.
func MetadataFor ¶
func MetadataFor(scope Scope, docID, title, source string, createdAt time.Time, chunk, chunkCount int) map[string]any
MetadataFor builds the canonical metadata map for one chunk.
func NewRetriever ¶
func NewRetriever(base KnowledgeBase, scope Scope, topK int, filter func(Metadata) bool) retriever.Retriever
NewRetriever returns an Eino retriever restricted to scope.
func ReadableBy ¶
ReadableBy returns the security predicate for a read. Blank request identities are omitted, avoiding the blank-as-wildcard vulnerability.
func ScopeForMetadata ¶
ScopeForMetadata returns the exact owning scope and target of a chunk.
func WritableBy ¶
WritableBy returns the document-level write predicate. A request may write its own personal scope and the group/tenant scopes it explicitly carries; read access alone is not enough to delete or move somebody else's document.
Types ¶
type AdminTools ¶
type AdminTools struct {
IsAdmin func(context.Context) bool
// contains filtered or unexported fields
}
AdminTools is the explicit read-only escape hatch for unattended owners that nobody logs into. The authorization function is supplied by the embedding application; core never guesses who an administrator is.
func NewAdminTools ¶
func NewAdminTools(base KnowledgeBase, isAdmin func(context.Context) bool) *AdminTools
NewAdminTools constructs administrator-only knowledge listing/search tools.
func (*AdminTools) List ¶
func (t *AdminTools) List() []tool.InvokableTool
List implements tools.Builtin.
type Entry ¶
type Entry struct {
DocID string `json:"docId"`
Title string `json:"title"`
Location string `json:"location,omitempty"`
ChunkCount int `json:"chunkCount"`
CreatedAt time.Time `json:"createdAt"`
Target Target `json:"target"`
}
Entry is one indexed document, not one chunk.
type FilteredKnowledgeBase ¶
type FilteredKnowledgeBase interface {
KnowledgeBase
SearchFiltered(ctx context.Context, scope Scope, query string, topK int, filter func(Metadata) bool) ([]*schema.Document, error)
}
FilteredKnowledgeBase is an optional extension for implementations that can apply metadata filters before ranking. It keeps fixed document allow-lists complete when a backend's top-K search would otherwise discard an allowed document before the facade can filter it.
type KnowledgeBase ¶
type KnowledgeBase interface {
Index(ctx context.Context, source Source) (string, error)
List(ctx context.Context, scope Scope, offset, limit int) (Page, error)
Delete(ctx context.Context, scope Scope, docID string) error
Move(ctx context.Context, scope Scope, docID string, target Target) (Entry, bool, error)
Search(ctx context.Context, scope Scope, query string, topK int) ([]*schema.Document, error)
}
KnowledgeBase is the facade implemented by optional knowledge modules.
type KnowledgeRetrieval ¶
KnowledgeRetrieval describes an explicit lookup, useful for unattended runs such as event triage that must not derive scope from untrusted input.
type Metadata ¶
type Metadata struct {
Owner string `json:"owner,omitempty"`
Group string `json:"group,omitempty"`
Tenant string `json:"tenant,omitempty"`
DocID string `json:"docId,omitempty"`
Title string `json:"title,omitempty"`
Source string `json:"source,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
Chunk int `json:"chunk,omitempty"`
ChunkCount int `json:"chunkCount,omitempty"`
}
Metadata is the portable, typed view of knowledge chunk metadata.
func ReadMetadata ¶
ReadMetadata converts Eino metadata into the domain view. It accepts the common JSON number forms as well as native ints because vector backends often deserialize metadata before returning it.
type RetrievalConfig ¶
RetrievalConfig controls automatic retrieval attached to agent runs.
type Scope ¶
Scope is the identity a knowledge document can be owned by and the identities a request may read. Blank group and tenant values mean that the corresponding scope does not exist; they never mean "any".
type ScopedRetriever ¶
type ScopedRetriever struct {
// contains filtered or unexported fields
}
ScopedRetriever adapts a KnowledgeBase to Eino's retriever contract. A backend remains free to use its own filter DSL; the facade's scope is still applied by the base implementation before documents leave it.
type Source ¶
type Source struct {
Scope Scope
Target Target
Title string
Text string
Location string
DocID string
CreatedAt time.Time
}
Source is content to index and its durable identity. DocID is required so indexing the same source replaces it instead of accumulating contradictory copies.
func NewPathSource ¶
NewPathSource constructs a source whose content is read from Location by the knowledge implementation.
func NewTextSource ¶
NewTextSource constructs a source whose content is already available.
type Target ¶
type Target string
Target is the knowledge base a document belongs to.
func ParseTarget ¶
ParseTarget parses the model-facing spelling of a target. "company" is accepted as a useful synonym for tenant, matching the Spring facade.
func TargetOrOwn ¶
TargetOrOwn returns the requested target, defaulting an omitted value to the caller's own knowledge base. Call ParseTarget when a typo must be rejected rather than treated as a default.
type Tools ¶
type Tools struct {
// contains filtered or unexported fields
}
Tools exposes intentional knowledge operations. Automatic retrieval belongs to the agent option; these tools are for writing, inspecting, and repairing a knowledge base when the model needs explicit control.
func NewTools ¶
func NewTools(base KnowledgeBase, home storage.Home, options ...ToolsOption) *Tools
NewTools constructs the knowledge tool family. A nil home is allowed for text indexing; path-based indexing is refused without a containment boundary. Remote fetching is intentionally outside this facade so a model cannot turn indexing into an SSRF primitive.
type ToolsOption ¶
type ToolsOption func(*Tools)
ToolsOption configures model-facing knowledge tools.
func WithPageSize ¶
func WithPageSize(size int) ToolsOption
WithPageSize sets the default listing page size, capped at 100.