Documentation
¶
Overview ¶
Package cache provides the graph tier of the two-tier .knowledge/ cache system. It serializes/deserializes the KnowledgeIndex to gob format and uses SHA-256 content hashes for file-level invalidation.
Package cache provides the vector tier of the two-tier .knowledge/ cache system. It stores and retrieves embedding vectors per file using efficient binary encoding, with model-aware invalidation.
Index ¶
- Variables
- type EmbedderInfo
- type GraphCache
- type KnowledgeIndexInfo
- type VectorCache
- func (vc *VectorCache) EnsureMeta(info EmbedderInfo) (invalidated bool, err error)
- func (vc *VectorCache) HasVectors(fileID string, contentHash string) bool
- func (vc *VectorCache) LoadVectors(fileID string, contentHash string) ([]float32, error)
- func (vc *VectorCache) PendingEmbeddings(idx KnowledgeIndexInfo) []string
- func (vc *VectorCache) SaveVectors(fileID string, contentHash string, vectors []float32) error
- type VectorMeta
Constants ¶
This section is empty.
Variables ¶
var ErrNoCacheFound = errors.New("cache: no cache found")
ErrNoCacheFound is returned when the .knowledge/ cache directory or its required files do not exist. Callers should fall back to a full load.
Functions ¶
This section is empty.
Types ¶
type EmbedderInfo ¶
type EmbedderInfo interface {
// Model returns the model identifier used for embedding.
Model() string
// Dimensions returns the dimensionality of the embedding vectors.
Dimensions() int
}
EmbedderInfo provides the model metadata needed by VectorCache for model-change detection. This mirrors the relevant subset of the embed.Embedder interface (Issue #19) so that this package compiles standalone before that package is merged.
type GraphCache ¶
type GraphCache struct{}
GraphCache provides save/load/stale-check for the graph tier cache.
func (*GraphCache) Load ¶
func (gc *GraphCache) Load(dir string) (*index.KnowledgeIndex, error)
Load deserializes the KnowledgeIndex from .knowledge/graph/index.gob under dir. Returns ErrNoCacheFound if the cache directory or index file does not exist.
func (*GraphCache) Save ¶
func (gc *GraphCache) Save(idx *index.KnowledgeIndex, dir string) error
Save serializes the KnowledgeIndex to .knowledge/graph/index.gob under dir and writes per-file SHA-256 checksums to .knowledge/graph/checksums. The .knowledge/ directory is auto-created if it does not exist.
func (*GraphCache) Stale ¶
func (gc *GraphCache) Stale(dir string, files []string) (changed, added, removed []string, err error)
Stale compares current file SHA-256 hashes against the cached checksums and returns which files have changed, been added, or been removed. Returns ErrNoCacheFound if the checksums file does not exist.
type KnowledgeIndexInfo ¶
type KnowledgeIndexInfo interface {
// AllFileIDs returns all file IDs in the index.
AllFileIDs() []string
// ContentHash returns the content hash for a file ID, or "" if unknown.
ContentHash(fileID string) string
}
KnowledgeIndexInfo provides the minimal interface to query which files exist in the knowledge index. This avoids importing the index package directly, allowing standalone compilation before PR #28 merges.
type VectorCache ¶
type VectorCache struct {
// contains filtered or unexported fields
}
VectorCache manages the storage and retrieval of embedding vectors in the .knowledge/vectors/ directory. It uses binary encoding for float32 slices and tracks model metadata for invalidation.
func NewVectorCache ¶
func NewVectorCache(dir string) *VectorCache
NewVectorCache creates a VectorCache rooted at the given project directory. The .knowledge/vectors/ subdirectory is created lazily on first write.
func (*VectorCache) EnsureMeta ¶
func (vc *VectorCache) EnsureMeta(info EmbedderInfo) (invalidated bool, err error)
EnsureMeta checks or initializes the meta.json file. If meta.json exists and the model or dimensions differ from the provided embedder config, all cached vectors are invalidated (the vectors directory is cleared) and a new meta.json is written. If meta.json does not exist, it is created. Returns true if vectors were invalidated.
func (*VectorCache) HasVectors ¶
func (vc *VectorCache) HasVectors(fileID string, contentHash string) bool
HasVectors checks if cached vectors exist for the given fileID and contentHash. Returns false if the vector file does not exist (indicating the file needs (re-)embedding due to content change or missing cache).
func (*VectorCache) LoadVectors ¶
func (vc *VectorCache) LoadVectors(fileID string, contentHash string) ([]float32, error)
LoadVectors reads embedding vectors for a file from the cache. Returns an error if the cached vectors do not exist or cannot be read. The number of float32 values is inferred from the file size.
func (*VectorCache) PendingEmbeddings ¶
func (vc *VectorCache) PendingEmbeddings(idx KnowledgeIndexInfo) []string
PendingEmbeddings returns file IDs from the index that need (re-)embedding. A file needs embedding if its vectors are not cached for its current content hash.
func (*VectorCache) SaveVectors ¶
func (vc *VectorCache) SaveVectors(fileID string, contentHash string, vectors []float32) error
SaveVectors writes embedding vectors for a file to the cache using efficient binary encoding (4-byte little-endian float32, no headers). The vectors directory is created if it does not exist.