entity

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package entity defines the core entities for the goRAG framework.

Package entity defines the core entities for the goRAG framework.

Package entity defines the core entities for the goRAG framework.

Package entity defines the core entities for the goRAG framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgenticMetadata

type AgenticMetadata struct {
	// Intent classification result
	Intent string `json:"intent"`

	// Sub-queries from decomposition
	SubQueries []string `json:"sub_queries"`

	// Extracted entity IDs
	EntityIDs []string `json:"entity_ids"`

	// Whether HyDE was applied
	HydeApplied bool `json:"hyde_applied"`

	// Cache hit status (nil = not checked, false = miss, true = hit)
	CacheHit *bool `json:"cache_hit,omitempty"`

	// Whether tool execution was performed
	ToolExecuted bool `json:"tool_executed"`

	// CRAG evaluation result (relevant/ambiguous/irrelevant)
	CRAGEvaluation string `json:"crag_evaluation"`

	// RAGAS evaluation scores
	RAGScores *RAGEScores `json:"rag_scores,omitempty"`

	// Original query before rewriting (if any)
	OriginalQueryText string `json:"original_query_text"`

	// Rewritten query text
	RewrittenQueryText string `json:"rewritten_query_text"`

	// Hypothetical document from HyDE
	HypotheticalDocument string `json:"hypothetical_document"`

	// Filter constraints extracted from query
	Filters map[string]any `json:"filters,omitempty"`

	// Step-back query for broader context
	StepBackQuery string `json:"step_back_query"`

	// Custom fields for extensibility
	Custom map[string]any `json:"custom,omitempty"`
}

AgenticMetadata provides strongly-typed metadata for agentic RAG operations. This eliminates the blackboard anti-pattern of using map[string]any.

func NewAgenticMetadata

func NewAgenticMetadata() *AgenticMetadata

NewAgenticMetadata creates a new AgenticMetadata instance.

func (*AgenticMetadata) GetCacheHit

func (m *AgenticMetadata) GetCacheHit() (hit bool, ok bool)

GetCacheHit returns the cache hit status and whether it was set.

func (*AgenticMetadata) LoadFromQuery

func (m *AgenticMetadata) LoadFromQuery(query *Query)

LoadFromQuery loads metadata from a Query's Metadata map. This is used for backward compatibility with existing code.

func (*AgenticMetadata) MergeToQuery

func (m *AgenticMetadata) MergeToQuery(query *Query)

MergeToQuery merges the metadata into a Query's Metadata map. This is used for backward compatibility with existing code.

func (*AgenticMetadata) SetCacheHit

func (m *AgenticMetadata) SetCacheHit(hit bool)

SetCacheHit sets the cache hit status.

func (*AgenticMetadata) Validate

func (m *AgenticMetadata) Validate() error

Validate checks if the metadata is valid.

type Chunk

type Chunk struct {
	ID         string         `json:"id"`
	DocumentID string         `json:"document_id"`         // ID of the root document
	ParentID   string         `json:"parent_id,omitempty"` // For Parent-Child Indexing (Hierarchical)
	Level      int            `json:"level"`               // 0: Root, 1: Parent, 2: Child
	Content    string         `json:"content"`
	Metadata   map[string]any `json:"metadata"`
	CreatedAt  time.Time      `json:"created_at"`
	StartIndex int            `json:"start_index"`
	EndIndex   int            `json:"end_index"`
	VectorID   string         `json:"vector_id,omitempty"`
}

Chunk represents a document chunk entity in the RAG system. It is a portion of a document that has been processed for vectorization.

func NewChunk

func NewChunk(id, documentID, content string, startIndex, endIndex int, metadata map[string]any) *Chunk

func (*Chunk) SetVectorID

func (c *Chunk) SetVectorID(vectorID string)

type Document

type Document struct {
	ID          string         `json:"id"`           // Unique identifier for the document
	Content     string         `json:"content"`      // The actual content of the document
	Metadata    map[string]any `json:"metadata"`     // Additional metadata about the document
	CreatedAt   time.Time      `json:"created_at"`   // Creation timestamp
	UpdatedAt   time.Time      `json:"updated_at"`   // Last update timestamp
	Source      string         `json:"source"`       // Source of the document
	ContentType string         `json:"content_type"` // Type of content (e.g., text, pdf, markdown)
}

Document represents a document entity in the RAG system. It contains the original content, metadata, and source information.

Related RAG concepts: - Document Processing: Part of the data pipeline for converting documents into vector representations - Data Freshness & Lifecycle: Tracks creation and update times for data lifecycle management

func NewDocument

func NewDocument(id, content, source, contentType string, metadata map[string]any) *Document

NewDocument creates a new document entity.

func (*Document) Update

func (d *Document) Update(content string, metadata map[string]any)

Update updates the document content and metadata.

type PipelineState

type PipelineState struct {
	// Query related fields
	Query         *Query `json:"query"`
	OriginalQuery *Query `json:"original_query"`

	// Retrieval related fields
	RetrievedChunks [][]*Chunk     `json:"retrieved_chunks"`
	ParallelResults [][]*Chunk     `json:"parallel_results"`
	RerankScores    []float32      `json:"rerank_scores"`
	Filters         map[string]any `json:"filters"`

	// Generation related fields
	Answer           string `json:"answer"`
	GenerationPrompt string `json:"generation_prompt"`

	// Self-RAG related fields
	SelfRagScore  float32 `json:"self_rag_score"`
	SelfRagReason string  `json:"self_rag_reason"`

	// Agentic RAG metadata (strongly-typed, eliminates blackboard anti-pattern)
	Agentic *AgenticMetadata `json:"agentic"`
}

PipelineState defines a strongly-typed state object for pipeline steps It contains all the fields that pipeline steps need to exchange data

func NewPipelineState

func NewPipelineState() *PipelineState

NewPipelineState creates a new pipeline state with empty values

type Query

type Query struct {
	ID        string         `json:"id"`         // Unique identifier for the query
	Text      string         `json:"text"`       // The actual query text
	Metadata  map[string]any `json:"metadata"`   // Additional metadata about the query
	CreatedAt time.Time      `json:"created_at"` // Creation timestamp
}

Query represents a query entity in the RAG system. It contains the user's query and related metadata.

Related RAG concepts: - Query Understanding & Intent: Represents the user's query intent - HyDE: Used as input for Hypothetical Document Embeddings - RAG-Fusion: Used as input for multi-query generation - Query Rewriting: Can be rewritten to improve retrieval effectiveness

func NewQuery

func NewQuery(id, text string, metadata map[string]any) *Query

NewQuery creates a new query entity.

type RAGEScores

type RAGEScores struct {
	Faithfulness     float32 `json:"faithfulness"`
	AnswerRelevance  float32 `json:"answer_relevance"`
	ContextPrecision float32 `json:"context_precision"`
	OverallScore     float32 `json:"overall_score"`
	Passed           bool    `json:"passed"`
}

RAGEScores holds RAGAS evaluation scores.

type RetrievalResult

type RetrievalResult struct {
	ID       string         `json:"id"`       // Unique identifier for the retrieval result
	QueryID  string         `json:"query_id"` // ID of the corresponding query
	Chunks   []*Chunk       `json:"chunks"`   // Retrieved chunks
	Scores   []float32      `json:"scores"`   // Relevance scores for the retrieved chunks
	Metadata map[string]any `json:"metadata"` // Additional metadata about the retrieval result
}

RetrievalResult represents a retrieval result entity in the RAG system. It contains the results of a search query, including the retrieved chunks and their scores.

Related RAG concepts: - Semantic Search: Represents the results of semantic search - Hybrid Retrieval: Can combine results from multiple retrieval strategies - Reranking Models: May be used to rerank the retrieved results - Context Augmentation: Used to augment the context for response generation - Ranking Quality: Scores represent the ranking quality of retrieved results

func NewRetrievalResult

func NewRetrievalResult(id, queryID string, chunks []*Chunk, scores []float32, metadata map[string]any) *RetrievalResult

NewRetrievalResult creates a new retrieval result entity.

type Vector

type Vector struct {
	ID       string         `json:"id"`       // Unique identifier for the vector
	Values   []float32      `json:"values"`   // The vector values
	ChunkID  string         `json:"chunk_id"` // ID of the corresponding chunk
	Metadata map[string]any `json:"metadata"` // Additional metadata about the vector
}

Vector represents a vector entity in the RAG system. It contains the vector representation of a document chunk.

Related RAG concepts: - Vector Embedding: Represents the vector embedding of a chunk - Semantic Search: Used for semantic search based on vector similarity - Cosine Similarity & Distance Metrics: Used to calculate similarity between vectors - Vector Database: Stored in vector databases for efficient retrieval

func NewVector

func NewVector(id string, values []float32, chunkID string, metadata map[string]any) *Vector

NewVector creates a new vector entity.

Jump to

Keyboard shortcuts

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