Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDocumentNotFound is returned when a document ID does not exist. ErrDocumentNotFound = errors.New("goreason: document not found") // ErrDocumentExists is returned when trying to ingest a duplicate path. ErrDocumentExists = errors.New("goreason: document already exists") // ErrUnsupportedFormat is returned for unrecognized file formats. ErrUnsupportedFormat = errors.New("goreason: unsupported document format") // ErrParsingFailed is returned when document parsing fails. ErrParsingFailed = errors.New("goreason: parsing failed") // ErrEmbeddingFailed is returned when embedding generation fails. ErrEmbeddingFailed = errors.New("goreason: embedding generation failed") ErrLLMUnavailable = errors.New("goreason: LLM provider unavailable") // ErrLLMRequestFailed is returned when an LLM request fails. ErrLLMRequestFailed = errors.New("goreason: LLM request failed") // ErrStoreClosed is returned when operating on a closed store. ErrStoreClosed = errors.New("goreason: store is closed") // ErrNoResults is returned when retrieval yields no matching chunks. ErrNoResults = errors.New("goreason: no results found") // ErrLowConfidence is returned when the answer confidence is below threshold. ErrLowConfidence = errors.New("goreason: answer confidence below threshold") // ErrInvalidConfig is returned for invalid configuration values. ErrInvalidConfig = errors.New("goreason: invalid configuration") // ErrVisionRequired is returned when a document requires vision processing // but no vision provider is configured. ErrVisionRequired = errors.New("goreason: vision provider required for this document") // ErrExternalParserRequired is returned when a legacy format needs an // external parsing service that is not configured. ErrExternalParserRequired = errors.New("goreason: external parser required for legacy format") )
Functions ¶
This section is empty.
Types ¶
type Answer ¶
type Answer struct {
Text string `json:"text"`
Found *bool `json:"found,omitempty"`
Confidence float64 `json:"confidence"`
Sources []Source `json:"sources"`
Reasoning []Step `json:"reasoning"`
RetrievalTrace *retrieval.SearchTrace `json:"retrieval_trace,omitempty"`
ModelUsed string `json:"model_used"`
Rounds int `json:"rounds"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
Answer represents the result of a query.
type Config ¶
type Config struct {
// DBPath is the full path to the SQLite database file.
// If empty, defaults to ~/.goreason/<DBName>.db
DBPath string `json:"db_path" yaml:"db_path"`
// DBName is the name for the database (used when DBPath is empty).
// Defaults to "goreason". The file will be <DBName>.db inside the
// storage directory (~/.goreason/ or working dir).
DBName string `json:"db_name" yaml:"db_name"`
// StorageDir controls where the database is created when DBPath
// is not explicitly set. Options: "home" (default) uses ~/.goreason/,
// "local" uses the current working directory.
StorageDir string `json:"storage_dir" yaml:"storage_dir"`
// LLM providers
Chat LLMConfig `json:"chat" yaml:"chat"`
Embedding LLMConfig `json:"embedding" yaml:"embedding"`
Vision LLMConfig `json:"vision" yaml:"vision"`
Translation LLMConfig `json:"translation" yaml:"translation"` // optional: fast model for query translation (defaults to Chat)
// Retrieval weights for RRF
WeightVector float64 `json:"weight_vector" yaml:"weight_vector"`
WeightFTS float64 `json:"weight_fts" yaml:"weight_fts"`
WeightGraph float64 `json:"weight_graph" yaml:"weight_graph"`
// Chunking
MaxChunkTokens int `json:"max_chunk_tokens" yaml:"max_chunk_tokens"`
ChunkOverlap int `json:"chunk_overlap" yaml:"chunk_overlap"`
// Graph building
SkipGraph bool `json:"skip_graph" yaml:"skip_graph"` // Skip knowledge graph extraction during ingest
GraphConcurrency int `json:"graph_concurrency" yaml:"graph_concurrency"` // Max parallel LLM calls for graph extraction (default 16)
// Reasoning
MaxRounds int `json:"max_rounds" yaml:"max_rounds"`
ConfidenceThreshold float64 `json:"confidence_threshold" yaml:"confidence_threshold"`
// External parsing
LlamaParse *LlamaParseConfig `json:"llamaparse,omitempty" yaml:"llamaparse,omitempty"`
// Embedding dimensions (must match model)
EmbeddingDim int `json:"embedding_dim" yaml:"embedding_dim"`
}
Config holds all configuration for the GoReason engine.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for local inference. Database is stored in ~/.goreason/goreason.db by default.
type Document ¶
type Document struct {
ID int64 `json:"id"`
Path string `json:"path"`
Filename string `json:"filename"`
Format string `json:"format"`
ContentHash string `json:"content_hash"`
ParseMethod string `json:"parse_method"`
Status string `json:"status"`
Metadata map[string]string `json:"metadata,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
Document represents an ingested document.
type Engine ¶
type Engine interface {
// Ingest parses, chunks, embeds, and builds graph for a document.
// Returns document ID. Skips if content hash unchanged.
Ingest(ctx context.Context, path string, opts ...IngestOption) (int64, error)
// Query runs a question through hybrid retrieval + multi-round reasoning.
Query(ctx context.Context, question string, opts ...QueryOption) (*Answer, error)
// Update re-checks a document by hash. Re-ingests if changed.
Update(ctx context.Context, path string) (bool, error)
// UpdateAll checks all ingested documents for changes.
UpdateAll(ctx context.Context) ([]UpdateResult, error)
// Delete removes a document and all associated data.
Delete(ctx context.Context, documentID int64) error
// ListDocuments returns all ingested documents.
ListDocuments(ctx context.Context) ([]Document, error)
// Store returns the underlying store for diagnostic access (e.g. eval ground-truth checks).
Store() *store.Store
// Close cleanly shuts down the engine.
Close() error
}
Engine is the main entry point for the Graph RAG engine.
type IngestOption ¶
type IngestOption func(*ingestOptions)
IngestOption configures ingestion behavior.
func WithForceReparse ¶
func WithForceReparse() IngestOption
WithForceReparse forces re-parsing even if the hash hasn't changed.
func WithMetadata ¶
func WithMetadata(metadata map[string]string) IngestOption
WithMetadata attaches custom metadata to the ingested document.
func WithParseMethod ¶
func WithParseMethod(method string) IngestOption
WithParseMethod overrides the automatic parse method selection.
type LLMConfig ¶
type LLMConfig struct {
Provider string `json:"provider" yaml:"provider"` // ollama, lmstudio, openrouter, xai, custom
Model string `json:"model" yaml:"model"`
BaseURL string `json:"base_url" yaml:"base_url"`
APIKey string `json:"api_key" yaml:"api_key"`
}
LLMConfig configures a single LLM provider endpoint.
type LlamaParseConfig ¶
type LlamaParseConfig struct {
APIKey string `json:"api_key" yaml:"api_key"`
BaseURL string `json:"base_url" yaml:"base_url"`
}
LlamaParseConfig configures the LlamaParse external parsing service.
type QueryOption ¶
type QueryOption func(*queryOptions)
QueryOption configures query behavior.
func WithJSONOutput ¶
func WithJSONOutput() QueryOption
WithJSONOutput enables structured JSON output mode. When enabled, the answer is post-processed into {"found": true/false, "response": "..."}. The Found field on Answer is set accordingly, and Text holds the response.
func WithMaxResults ¶
func WithMaxResults(n int) QueryOption
WithMaxResults sets the maximum number of chunks to retrieve.
func WithMaxRounds ¶
func WithMaxRounds(n int) QueryOption
WithMaxRounds overrides the maximum reasoning rounds for this query.
func WithWeights ¶
func WithWeights(vec, fts, graph float64) QueryOption
WithWeights overrides the retrieval weights for this query.
type Source ¶
type Source struct {
ChunkID int64 `json:"chunk_id"`
DocumentID int64 `json:"document_id"`
Filename string `json:"filename"`
Content string `json:"content"`
Heading string `json:"heading"`
PageNumber int `json:"page_number"`
Score float64 `json:"score"`
}
Source represents a retrieved source chunk backing an answer.
type Step ¶
type Step struct {
Round int `json:"round"`
Action string `json:"action"`
Input string `json:"input,omitempty"`
Output string `json:"output,omitempty"`
Prompt string `json:"prompt,omitempty"`
Response string `json:"response,omitempty"`
Validation string `json:"validation,omitempty"`
ChunksUsed int `json:"chunks_used,omitempty"`
Tokens int `json:"tokens,omitempty"`
ElapsedMs int64 `json:"elapsed_ms,omitempty"`
Issues []string `json:"issues,omitempty"`
}
Step represents a single reasoning round in the multi-round pipeline.