Documentation
¶
Overview ¶
Package vfsindex bridges a vfs.MountSession into brain knowledge objects.
Canonical architecture: docs/knowledge.md. This package is only the artifact ingest path (IndexPath, IndexFile, UnindexPath).
VFS and brain work alone or together. This package is the optional composition layer: it imports both, while vfs and brain never import each other.
Model ¶
Each text-like virtual file becomes a brain Document (parent) with Chunk parts. The row contract (ids, property types, versions, and replace rules) is "File mirror rows" in docs/knowledge.md. In-process writers should call IndexPath or DocumentID rather than insert rows themselves.
Document id = UUID v5, namespace a1b2c3d4-e5f6-7890-abcd-ef1234567890,
name = Namespace.String() + 0x00 + virtual path
Document.properties.vfs_path, source_version, size, mtime, media_type
Chunk id = from the chunk's content (Engine.PutTree)
Chunk.properties.start_line, end_line, byte_start, byte_end
Chunk.properties.block_id, heading_path = the block id, when structured
Chunk.Content = chunk body
Plain text streams through content-defined chunking (ChunkSizes): a boundary depends only on nearby bytes, so an edit changes only the chunks around it. Markdown, Docs and Sheets chunk by block. A file whose FileInfo.Version and readers match the Document is not opened. A re-index embeds and writes only chunks whose text changed. Live file bytes stay the source of truth.
Mounts that are not indexed ¶
A member mounted with vfs.Member.NotIndexed (MountSpec.NotIndexed) is not indexed: index_file refuses its files, and IndexPath skips them. The turn does not walk mounts, subscribe to remote changes, or re-index after WriteFile.
Single pipeline ¶
File bytes become brain chunks only through IndexPath (or UnindexPath). The turn calls that from index_file and unindex. A host calls IndexPath from its own system. A version match returns PathSkipped without reading the file.
Session-visible body ¶
IndexPath uses MountSession.ReadText (structured types) and MountSession.Open (other text). Writes are write-through, so a later index_file sees the last persist.
In a turn ¶
A turn with a brain and a workspace builds one MountIndexer and registers index_file / unindex over it. Keeping chunks current after the sandbox exits is the host's storage pipeline: it calls IndexPath itself.
Kinds ¶
Hosts that use a non-empty kind catalog should register MountIndexKinds() (or equivalent fields) before indexing. Open-catalog engines accept any props.
Content search over mounts is brain search on Chunks with vfs_path. Live grep is run_command → rg on the FUSE tree. This package does not implement grep.
Index ¶
- Constants
- Variables
- func MountIndexKinds() []brain.KindSpec
- type ChunkSizes
- type MountIndexer
- func (x *MountIndexer) DocumentID(virtualPath string) uuid.UUID
- func (x *MountIndexer) IndexFile(ctx context.Context, virtualPath string, st vfs.FileInfo) (PathIndexResult, error)
- func (x *MountIndexer) IndexPath(ctx context.Context, virtualPath string) (PathIndexResult, error)
- func (x *MountIndexer) UnindexPath(ctx context.Context, virtualPath string) (bool, error)
- type PathIndexResult
- type ReadersFunc
Constants ¶
const ( PropVFSPath = "vfs_path" PropSize = "size" PropMTime = "mtime" PropSourceVersion = "source_version" PropMediaType = "media_type" PropStartLine = "start_line" PropEndLine = "end_line" PropByteStart = "byte_start" PropByteEnd = "byte_end" PropBlockID = "block_id" PropHeadingPath = "heading_path" )
Property keys written on mount-indexed objects.
const ( DefaultDocumentKind = "Document" DefaultChunkKind = "Chunk" )
Default kind names (host may override on MountIndexer).
const DefaultMaxIndexBytes = 64 << 20 // 64 MiB per file
DefaultMaxIndexBytes caps how much of a plain-text file is indexed.
Variables ¶
var DefaultChunkSizes = ChunkSizes{Min: 1 << 10, Avg: 2 << 10, Max: 8 << 10}
DefaultChunkSizes suits current embedding models (about 500 tokens a chunk).
Functions ¶
func MountIndexKinds ¶
MountIndexKinds returns KindSpecs for catalog mode when indexing mounts. Fields are optional so pure knowledge Documents/Chunks without vfs_path remain valid.
Types ¶
type ChunkSizes ¶ added in v0.5.0
type ChunkSizes struct {
// Min is the smallest chunk, except the last one of a file. Default 1 KiB.
Min int
// Avg is the target mean chunk size. Default 2 KiB.
Avg int
// Max is the largest chunk. A chunk that reaches Max ends at its last
// line end, or at Max when it has no line end past Min. Default 8 KiB.
Max int
}
ChunkSizes bounds the content-defined chunks a file is split into, in bytes. A chunk ends at the first line end after a content-defined cut point, so boundaries depend only on nearby bytes: an edit changes the chunks around it, and the chunks before and after it keep their text (and so their brain ids and vectors). Size them for the embedding model: about 4 bytes of English text make one token.
type MountIndexer ¶
type MountIndexer struct {
VFS *vfs.MountSession
Brain *brain.Engine
Scope brain.Scope
DocumentKind string // default Document
ChunkKind string // default Chunk
// Chunking sizes the chunks; zero fields take DefaultChunkSizes.
Chunking ChunkSizes
// MaxIndexBytes caps how much of a plain-text file is read and indexed
// (default DefaultMaxIndexBytes). Structured files (Markdown, Docs,
// Sheets) are read whole, up to vfs.MaxReadFileBytes.
MaxIndexBytes int64
// Readers returns the source ACL for a file: the principals allowed to
// read it (for example from Drive or SharePoint sharing). Its result is
// stored on the Document and every Chunk, so search only shows the file
// to scopes holding one of those principals. Nil, or an empty result,
// leaves the file visible to every scope that covers Scope.Namespace.
Readers ReadersFunc
}
MountIndexer streams text-like mount files into brain Document + Chunk objects.
func NewMountIndexer ¶
func NewMountIndexer(ms *vfs.MountSession, eng *brain.Engine, scope brain.Scope) (*MountIndexer, error)
NewMountIndexer validates required fields. Scope.Namespace must be set (brain Put requires namespace attrs).
func (*MountIndexer) DocumentID ¶
func (x *MountIndexer) DocumentID(virtualPath string) uuid.UUID
DocumentID returns the stable brain id for a virtual path under this scope.
func (*MountIndexer) IndexFile ¶ added in v0.5.0
func (x *MountIndexer) IndexFile(ctx context.Context, virtualPath string, st vfs.FileInfo) (PathIndexResult, error)
IndexFile indexes a path already known to exist (caller Stat'd). It does not Stat again, so batch tools can validate once then index.
func (*MountIndexer) IndexPath ¶
func (x *MountIndexer) IndexPath(ctx context.Context, virtualPath string) (PathIndexResult, error)
IndexPath indexes one virtual file, or removes its mirror when the file is missing.
func (*MountIndexer) UnindexPath ¶
UnindexPath soft-deletes the brain Document/Chunks for virtualPath without touching the VFS file. Returns true when a mirror was present and removed, false when nothing was indexed (idempotent noop).
type PathIndexResult ¶
type PathIndexResult string
PathIndexResult is a compact outcome of indexing one path (indexed|skipped|removed|directory). Used by agent tools and hosts.
const ( // PathIndexed means Document/Chunks were written or re-chunked. PathIndexed PathIndexResult = "indexed" // PathSkipped means version match, binary, non-text, or a NotIndexed mount. PathSkipped PathIndexResult = "skipped" // PathRemoved means the path was missing and any brain mirror was soft-deleted. PathRemoved PathIndexResult = "removed" // PathDirectory means the path is a directory (IndexPath does nothing for a directory). PathDirectory PathIndexResult = "directory" )