rag

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent represents a simplified RAG agent that hides OpenAI SDK details

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
) (*Agent, error)

NewAgent creates a new simplified RAG agent

func (*Agent) GenerateEmbedding

func (agent *Agent) GenerateEmbedding(content string) ([]float64, error)

GenerateEmbedding creates a vector embedding for the given text content

func (*Agent) GetEmbeddingDimension added in v0.0.8

func (agent *Agent) GetEmbeddingDimension() int

GetEmbeddingDimension returns the dimension of the embedding vectors generated by the agent's model

func (*Agent) GetLastEmbeddingRequestJSON added in v1.0.2

func (agent *Agent) GetLastEmbeddingRequestJSON() (string, error)

GetLastEmbeddingRequestJSON returns the last embedding request as JSON string

func (*Agent) GetLastEmbeddingRequestMetadata added in v1.0.2

func (agent *Agent) GetLastEmbeddingRequestMetadata() EmbeddingRequestMetadata

GetLastEmbeddingRequestMetadata returns metadata about the last embedding request

func (*Agent) GetLastEmbeddingResponseJSON added in v1.0.2

func (agent *Agent) GetLastEmbeddingResponseJSON() (string, error)

GetLastEmbeddingResponseJSON returns the last embedding response as JSON string

func (*Agent) GetLastEmbeddingResponseMetadata added in v1.0.2

func (agent *Agent) GetLastEmbeddingResponseMetadata() EmbeddingResponseMetadata

GetLastEmbeddingResponseMetadata returns metadata about the last embedding response

func (*Agent) GetModelID added in v0.0.7

func (agent *Agent) GetModelID() string

func (*Agent) GetName added in v0.0.3

func (agent *Agent) GetName() string

func (*Agent) Kind

func (agent *Agent) Kind() agents.Kind

Kind returns the agent type

func (*Agent) LoadStore added in v0.0.5

func (agent *Agent) LoadStore(storeFilePath string) error

func (*Agent) PersistStore added in v0.0.5

func (agent *Agent) PersistStore(storeFilePath string) error

func (*Agent) SaveEmbedding

func (agent *Agent) SaveEmbedding(content string) error

SaveEmbedding generates and saves an embedding for the given content

func (*Agent) SearchSimilar

func (agent *Agent) SearchSimilar(content string, limit float64) ([]VectorRecord, error)

SearchSimilar searches for similar records based on content limit is the minimum cosine similarity threshold (1.0 = exact match, 0.0 = no similarity)

func (*Agent) SearchTopN

func (agent *Agent) SearchTopN(content string, limit float64, n int) ([]VectorRecord, error)

SearchTopN searches for top N similar records based on content limit is the minimum cosine similarity threshold (1.0 = exact match, 0.0 = no similarity) n is the maximum number of results to return

func (*Agent) StoreFileExists added in v0.0.5

func (agent *Agent) StoreFileExists(storeFilePath string) bool

type AgentOption

type AgentOption func(*BaseAgent)

type BaseAgent

type BaseAgent struct {
	EmbeddingParams openai.EmbeddingNewParams
	// contains filtered or unexported fields
}

func NewBaseAgent

func NewBaseAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.EmbeddingNewParams,
	options ...AgentOption,
) (ragAgent *BaseAgent, err error)

NewBaseAgent creates a new RAG agent with OpenAI SDK integration

func (*BaseAgent) GenerateEmbeddingVector

func (agent *BaseAgent) GenerateEmbeddingVector(content string) (embeddingVector []float64, err error)

GenerateEmbeddingVector creates a vector embedding for the given text content using the agent's embedding model

func (*BaseAgent) GenerateThenSaveEmbeddingVector

func (agent *BaseAgent) GenerateThenSaveEmbeddingVector(content string) (err error)

GenerateThenSaveEmbeddingVector creates a vector embedding for the given text content

func (*BaseAgent) GetEmbeddingDimension added in v0.0.8

func (agent *BaseAgent) GetEmbeddingDimension() int

GetEmbeddingDimension returns the dimension of the embedding vectors generated by the agent's model

func (*BaseAgent) GetLastEmbeddingRequestJSON added in v1.0.2

func (agent *BaseAgent) GetLastEmbeddingRequestJSON() (string, error)

GetLastEmbeddingRequestJSON returns the last embedding request as JSON string

func (*BaseAgent) GetLastEmbeddingRequestMetadata added in v1.0.2

func (agent *BaseAgent) GetLastEmbeddingRequestMetadata() EmbeddingRequestMetadata

GetLastEmbeddingRequestMetadata returns metadata about the last embedding request

func (*BaseAgent) GetLastEmbeddingResponseJSON added in v1.0.2

func (agent *BaseAgent) GetLastEmbeddingResponseJSON() (string, error)

GetLastEmbeddingResponseJSON returns the last embedding response as JSON string

func (*BaseAgent) GetLastEmbeddingResponseMetadata added in v1.0.2

func (agent *BaseAgent) GetLastEmbeddingResponseMetadata() EmbeddingResponseMetadata

GetLastEmbeddingResponseMetadata returns metadata about the last embedding response

func (*BaseAgent) SearchSimilarities

func (agent *BaseAgent) SearchSimilarities(content string, limit float64) (results []stores.VectorRecord, err error)

SearchSimilarities searches the vector store for similar records based on the embedding of the provided content and returns the top results up to the specified limit Parameters:

  • content: the text content to generate an embedding for searching.
  • limit: the minimum cosine distance similarity threshold. 1.0 means exact match, 0.0 means no similarity.

func (*BaseAgent) SearchTopNSimilarities

func (agent *BaseAgent) SearchTopNSimilarities(content string, limit float64, n int) (results []stores.VectorRecord, err error)

SearchTopNSimilarities searches the vector store for similar records based on the embedding of the provided content and returns the top N results above the specified similarity limit Parameters:

  • content: the text content to generate an embedding for searching.
  • limit: the minimum cosine distance similarity threshold. 1.0 means exact match, 0.0 means no similarity.
  • n: the maximum number of top similar records to return.

type EmbeddingRequestMetadata added in v1.0.2

type EmbeddingRequestMetadata struct {
	Model          string
	InputLength    int
	EncodingFormat string
	Dimensions     int
	Timestamp      time.Time
}

EmbeddingRequestMetadata contains metadata about an embedding request

type EmbeddingResponseMetadata added in v1.0.2

type EmbeddingResponseMetadata struct {
	Model           string
	EmbeddingIndex  int
	VectorDimension int
	PromptTokens    int
	TotalTokens     int
	ResponseTime    int64 // in milliseconds
	Timestamp       time.Time
}

EmbeddingResponseMetadata contains metadata about an embedding response

type Metrics added in v1.0.2

type Metrics struct {
	TotalEmbeddings  int
	TotalDimensions  int
	TotalProcessTime time.Duration
	TotalCharacters  int
	SearchOperations int
	TotalSearchTime  time.Duration
}

Metrics tracks performance and usage metrics for RAG embedding operations

func NewMetrics added in v1.0.2

func NewMetrics() *Metrics

NewMetrics creates a new Metrics instance

func (*Metrics) AvgCharsPerDocument added in v1.0.2

func (m *Metrics) AvgCharsPerDocument() int

AvgCharsPerDocument returns the average number of characters per document

func (*Metrics) AvgDimensions added in v1.0.2

func (m *Metrics) AvgDimensions() int

AvgDimensions returns the average number of dimensions per embedding

func (*Metrics) AvgEmbeddingTime added in v1.0.2

func (m *Metrics) AvgEmbeddingTime() time.Duration

AvgEmbeddingTime returns the average time per embedding operation

func (*Metrics) AvgOperationTime added in v1.0.2

func (m *Metrics) AvgOperationTime() time.Duration

AvgOperationTime returns the average time per operation (embedding or search)

func (*Metrics) AvgSearchTime added in v1.0.2

func (m *Metrics) AvgSearchTime() time.Duration

AvgSearchTime returns the average time per search operation

func (*Metrics) CostPerDocument added in v1.0.2

func (m *Metrics) CostPerDocument(costPerThousandChars float64) float64

CostPerDocument returns the estimated cost per document costPerThousandChars is the cost per 1000 characters (e.g., 0.0001 USD)

func (*Metrics) EstimateCost added in v1.0.2

func (m *Metrics) EstimateCost(costPerThousandChars float64) float64

EstimateCost estimates the cost of embeddings based on character count costPerThousandChars is the cost per 1000 characters (e.g., 0.0001 USD)

func (*Metrics) RecordEmbedding added in v1.0.2

func (m *Metrics) RecordEmbedding(content string, dimensions int, duration time.Duration)

RecordEmbedding records metrics for a single embedding operation

func (*Metrics) RecordSearch added in v1.0.2

func (m *Metrics) RecordSearch(duration time.Duration)

RecordSearch records metrics for a search operation

func (*Metrics) Reset added in v1.0.2

func (m *Metrics) Reset()

Reset clears all metrics

func (*Metrics) Throughput added in v1.0.2

func (m *Metrics) Throughput() float64

Throughput returns operations per second

func (*Metrics) TotalOperations added in v1.0.2

func (m *Metrics) TotalOperations() int

TotalOperations returns the total number of operations (embeddings + searches)

func (*Metrics) TotalTime added in v1.0.2

func (m *Metrics) TotalTime() time.Duration

TotalTime returns the total time spent on all operations

type SearchSettings added in v0.0.8

type SearchSettings struct {
	SimilarityLimit float64
	MaxSimilarities int
}

type VectorRecord

type VectorRecord struct {
	ID        string
	Prompt    string
	Embedding []float64
	Metadata  map[string]any
	// CosineSimilarity
	Similarity float64
}

VectorRecord represents a vector record with prompt and embedding

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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