knowledge

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 17 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

Index

Constants

View Source
const (
	DefaultLimit  = 5
	PageLimit     = 100
	CitationLimit = 64 * 1024
	// MaxPrefixBytes bounds a plugin storage key prefix.
	MaxPrefixBytes = 128
)

Query and citation bounds of the protocol.

View Source
const (
	Tokens = 256
)

Tokens is the largest chunk in model tokens; consecutive chunks overlap.

Variables

This section is empty.

Functions

func AppendVector

func AppendVector(values []int8, bytes []byte, dimension int) ([]int8, float32, error)

AppendVector checks a stored vector as DecodeVector does and appends its components to values, so that many vectors share one allocation. It returns the norm of the appended components.

func CitationURL

func CitationURL(citation protocol.KnowledgeCitation) string

CitationURL is the link a Node generates for an indexed chunk.

func Excluded

func Excluded(name string) bool

Excluded reports a file or directory name that is never indexed: credentials, keys and tool configuration.

func Field

func Field(text string) string

Field folds only derived search fields; source text stays intact.

func Glob

func Glob(pattern string) (*regexp.Regexp, error)

Glob compiles a collection filter with the reference matcher's defaults: "*" and "?" cross path separators, "**" spans whole directories, classes negate with "!" or "^", braces alternate and a backslash escapes. doublestar stops "*" at a separator, so the pattern is translated instead.

func Hash

func Hash(value string) bool

Hash reports a lowercase BLAKE3 hex digest.

func Index

func Index(text string) string

Index preserves a phrase stream followed by adjacent CJK pairs.

func Native

func Native(path string) (string, error)

Native maps an absolute source path to the directory the system resolves it to: macOS reaches /var and /tmp through links into /private.

func Phrase

func Phrase(text string) string

Phrase treats one explicit search term as a literal phrase.

func Protected

func Protected(path string) bool

Protected reports a path with an excluded component.

func Query

func Query(text string) string

Query matches independent words and adjacent CJK pairs in stable order.

func ValidateCitation

func ValidateCitation(request protocol.KnowledgeCitationRequest) error

ValidateCitation checks a citation read.

func ValidateDefinition

func ValidateDefinition(definition protocol.KnowledgeDefinition) error

ValidateDefinition checks the shape of a collection definition.

func ValidateQuery

func ValidateQuery(query protocol.KnowledgeQuery) error

ValidateQuery checks a search and its filters.

Types

type Chunk

type Chunk struct {
	Start, End          int
	FirstLine, LastLine uint32
	Heading             *string
}

Chunk is one source-aligned token window with its Markdown heading.

func Split

func Split(text string, offsets [][2]int) ([]Chunk, error)

Split windows text along its token byte ranges, preferring a paragraph boundary that keeps at least half a window.

type Direction

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

Direction is a query embedding checked once for many comparisons.

func NewDirection

func NewDirection(values []float32) (Direction, error)

NewDirection checks a query embedding as Vector.Cosine does.

func (Direction) Cosine

func (query Direction) Cosine(values []int8, norm float32) float32

Cosine compares the query with the components and norm of one stored vector of its dimension. It is the arithmetic of Vector.Cosine, in the same order, so both give the same bits.

type Ranked

type Ranked struct {
	Key   string
	Score float32
}

Ranked is one fused key with its reciprocal-rank score.

func Fuse

func Fuse(keyword, semantic []string) []Ranked

Fuse merges two ranked lists by reciprocal rank. A key counts once per list; equal scores order by key.

type Vector

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

Vector is a compact derived embedding: signed bytes under one scale.

func DecodeVector

func DecodeVector(bytes []byte, dimension int) (Vector, error)

DecodeVector reads a stored vector of the collection's dimension.

func Quantize

func Quantize(values []float32) (Vector, error)

Quantize keeps the direction of an embedding in one byte per component.

func (Vector) Cosine

func (vector Vector) Cosine(query []float32) (float32, error)

Cosine compares the stored direction with a query embedding.

func (Vector) Encode

func (vector Vector) Encode() []byte

Encode stores the scale followed by one byte per component.

Directories

Path Synopsis
Package service indexes knowledge collections and answers queries and citation reads.
Package service indexes knowledge collections and answers queries and citation reads.
Package source reads the files of a knowledge collection.
Package source reads the files of a knowledge collection.

Jump to

Keyboard shortcuts

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