index

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package index orchestrates atomic Stroma index rebuilds and searches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOptions

type BuildOptions struct {
	Path          string
	ReuseFromPath string
	Embedder      embed.Embedder

	// MaxChunkTokens sets the approximate maximum number of tokens (words)
	// per chunk. Sections that exceed this limit are split into smaller
	// sub-sections. Zero disables token-budget splitting.
	MaxChunkTokens int

	// ChunkOverlapTokens sets the approximate number of overlapping tokens
	// between adjacent sub-sections when a section is split. Zero disables
	// overlap.
	ChunkOverlapTokens int

	// Quantization controls the vector storage format. Supported values
	// are "float32" (default) and "int8". Int8 reduces storage by 4x at
	// the cost of minor precision loss.
	Quantization string
}

BuildOptions controls how a Stroma index is rebuilt.

type BuildResult

type BuildResult struct {
	Path                string
	RecordCount         int
	ChunkCount          int
	ReusedRecordCount   int
	ReusedChunkCount    int
	EmbeddedChunkCount  int
	EmbedderDimension   int
	EmbedderFingerprint string
	ContentFingerprint  string
}

BuildResult summarizes a completed rebuild.

func Rebuild

func Rebuild(ctx context.Context, records []corpus.Record, options BuildOptions) (*BuildResult, error)

Rebuild atomically recreates the index at the requested path.

type RecordQuery

type RecordQuery struct {
	Refs  []string
	Kinds []string
}

RecordQuery filters records from an opened snapshot.

type SearchHit

type SearchHit struct {
	ChunkID   int64
	Ref       string
	Kind      string
	Title     string
	SourceRef string
	Heading   string
	Content   string
	Metadata  map[string]string
	Score     float64
}

SearchHit is one retrieved section.

func Search(ctx context.Context, query SearchQuery) ([]SearchHit, error)

Search returns semantically close sections from an existing index.

type SearchQuery

type SearchQuery struct {
	Path     string
	Text     string
	Limit    int
	Kinds    []string
	Embedder embed.Embedder
}

SearchQuery defines one semantic search.

type Section

type Section struct {
	ChunkID   int64
	Ref       string
	Kind      string
	Title     string
	SourceRef string
	Heading   string
	Content   string
	Metadata  map[string]string
	Embedding []float64
}

Section is one stored section from a Stroma snapshot.

type SectionQuery

type SectionQuery struct {
	Refs              []string
	Kinds             []string
	IncludeEmbeddings bool
}

SectionQuery filters sections from an opened snapshot.

type Snapshot

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

Snapshot is one opened Stroma index snapshot.

func OpenSnapshot

func OpenSnapshot(ctx context.Context, path string) (*Snapshot, error)

OpenSnapshot opens a read-only Stroma snapshot.

func (*Snapshot) Close

func (s *Snapshot) Close() error

Close releases the opened snapshot handle.

func (*Snapshot) Path

func (s *Snapshot) Path() string

Path returns the opened snapshot path.

func (*Snapshot) Records

func (s *Snapshot) Records(ctx context.Context, query RecordQuery) ([]corpus.Record, error)

Records returns records from the opened snapshot.

func (*Snapshot) Search

func (s *Snapshot) Search(ctx context.Context, query SnapshotSearchQuery) ([]SearchHit, error)

Search runs a hybrid text search (vector + FTS5) against the opened snapshot.

func (*Snapshot) SearchVector

func (s *Snapshot) SearchVector(ctx context.Context, query VectorSearchQuery) ([]SearchHit, error)

SearchVector runs a vector search against the opened snapshot.

func (*Snapshot) Sections

func (s *Snapshot) Sections(ctx context.Context, query SectionQuery) ([]Section, error)

Sections returns sections from the opened snapshot.

func (*Snapshot) Stats

func (s *Snapshot) Stats(ctx context.Context) (*Stats, error)

Stats inspects the opened snapshot.

type SnapshotSearchQuery

type SnapshotSearchQuery struct {
	Text     string
	Limit    int
	Kinds    []string
	Embedder embed.Embedder
}

SnapshotSearchQuery defines one text search against an opened snapshot.

type Stats

type Stats struct {
	Path                string
	RecordCount         int
	ChunkCount          int
	KindCounts          map[string]int
	SchemaVersion       string
	EmbedderDimension   int
	EmbedderFingerprint string
	ContentFingerprint  string
	CreatedAt           string
}

Stats describes a built Stroma index.

func ReadStats

func ReadStats(ctx context.Context, path string) (*Stats, error)

ReadStats inspects an existing index.

type VectorSearchQuery

type VectorSearchQuery struct {
	Embedding []float64
	Limit     int
	Kinds     []string
}

VectorSearchQuery defines one vector search against an opened snapshot.

Jump to

Keyboard shortcuts

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