Documentation
¶
Index ¶
- type Agent
- func (agent *Agent) GenerateEmbedding(content string) ([]float64, error)
- func (agent *Agent) GetConfig() agents.Config
- func (agent *Agent) GetContext() context.Context
- func (agent *Agent) GetEmbeddingDimension() int
- func (agent *Agent) GetLastRequestJSON() (string, error)
- func (agent *Agent) GetLastRequestRawJSON() string
- func (agent *Agent) GetLastResponseJSON() (string, error)
- func (agent *Agent) GetLastResponseRawJSON() string
- func (agent *Agent) GetModelConfig() models.Config
- func (agent *Agent) GetModelID() string
- func (agent *Agent) GetName() string
- func (agent *Agent) Kind() agents.Kind
- func (agent *Agent) LoadStore(storeFilePath string) error
- func (agent *Agent) PersistStore(storeFilePath string) error
- func (agent *Agent) SaveEmbedding(content string) error
- func (agent *Agent) SaveEmbeddingIntoMemoryVectorStore(content string) error
- func (agent *Agent) SearchSimilar(content string, limit float64) ([]VectorRecord, error)
- func (agent *Agent) SearchTopN(content string, limit float64, n int) ([]VectorRecord, error)
- func (agent *Agent) SetConfig(config agents.Config)
- func (agent *Agent) SetContext(ctx context.Context)
- func (agent *Agent) SetModelConfig(config models.Config)
- func (agent *Agent) StoreFileExists(storeFilePath string) bool
- type AgentOption
- type BaseAgent
- func (agent *BaseAgent) GenerateEmbeddingVector(content string) (embeddingVector []float64, err error)
- func (agent *BaseAgent) GenerateThenSaveEmbeddingVector(content string) (err error)
- func (agent *BaseAgent) GetConfig() agents.Config
- func (agent *BaseAgent) GetContext() context.Context
- func (agent *BaseAgent) GetEmbeddingDimension() int
- func (agent *BaseAgent) GetLastRequestRawJSON() string
- func (agent *BaseAgent) GetLastRequestSON() (string, error)
- func (agent *BaseAgent) GetLastResponseJSON() (string, error)
- func (agent *BaseAgent) GetLastResponseRawJSON() string
- func (agent *BaseAgent) SaveLastEmbeddingRequest() error
- func (agent *BaseAgent) SaveLastEmbeddingResponse(embeddingResponse *openai.CreateEmbeddingResponse) error
- func (agent *BaseAgent) SearchSimilarities(content string, limit float64) (results []stores.VectorRecord, err error)
- func (agent *BaseAgent) SearchTopNSimilarities(content string, limit float64, n int) (results []stores.VectorRecord, err error)
- func (agent *BaseAgent) SetConfig(config agents.Config)
- func (agent *BaseAgent) SetContext(ctx context.Context)
- type RagAgentOption
- type SearchSettings
- type VectorRecord
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, options ...any, ) (*Agent, error)
NewAgent creates a new simplified RAG agent
func (*Agent) GenerateEmbedding ¶
GenerateEmbedding creates a vector embedding for the given text content
func (*Agent) GetContext ¶ added in v1.2.2
GetContext returns the agent's context
func (*Agent) GetEmbeddingDimension ¶ added in v0.0.8
GetEmbeddingDimension returns the dimension of the embedding vectors generated by the agent's model
func (*Agent) GetLastRequestJSON ¶ added in v1.1.2
func (*Agent) GetLastRequestRawJSON ¶ added in v1.1.2
func (*Agent) GetLastResponseJSON ¶ added in v1.1.2
func (*Agent) GetLastResponseRawJSON ¶ added in v1.1.2
func (*Agent) GetModelConfig ¶ added in v1.0.8
GetModelConfig returns the model configuration
func (*Agent) GetModelID ¶ added in v0.0.7
func (*Agent) PersistStore ¶ added in v0.0.5
func (*Agent) SaveEmbedding ¶
SaveEmbedding generates and saves an embedding for the given content into the in memory agent's vector store
func (*Agent) SaveEmbeddingIntoMemoryVectorStore ¶ added in v1.1.3
SaveEmbeddingIntoMemoryVectorStore generates and saves an embedding for the given content into the in memory agent's vector store
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 ¶
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) SetContext ¶ added in v1.2.2
SetContext updates the agent's context
func (*Agent) SetModelConfig ¶ added in v1.0.8
SetModelConfig updates the model configuration Note: For RAG agents, changing the model config requires recreating the agent as the embedding parameters are set during initialization
func (*Agent) StoreFileExists ¶ added in v0.0.5
type AgentOption ¶
type AgentOption func(*BaseAgent)
func WithInMemoryStore ¶ added in v1.3.1
func WithInMemoryStore() AgentOption
WithInMemoryStore configures the agent to use in-memory vector storage This is the default behavior, so this option is only needed if you want to be explicit
func WithRedisStore ¶ added in v1.3.1
func WithRedisStore(config stores.RedisConfig, dimension int) AgentOption
WithRedisStore configures the agent to use Redis as the vector storage backend Parameters:
- config: Redis connection configuration (address, password, DB, index name)
- dimension: the dimension of embedding vectors (must match your embedding model)
Example:
ragAgent, err := rag.NewBaseAgent(
ctx,
agents.Config{EngineURL: "http://localhost:12434/engines/llama.cpp/v1"},
openai.EmbeddingNewParams{Model: "ai/mxbai-embed-large"},
rag.WithRedisStore(stores.RedisConfig{
Address: "localhost:6379",
Password: "",
DB: 0,
IndexName: "my_rag_index",
}, 1024),
)
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 ¶
GenerateThenSaveEmbeddingVector creates a vector embedding for the given text content
func (*BaseAgent) GetContext ¶ added in v1.2.2
GetContext returns the agent's context
func (*BaseAgent) GetEmbeddingDimension ¶ added in v0.0.8
Embedding vector dimension: the size of the produced vector (e.g., 384, 768, 1024, 3072 dimensions). GetEmbeddingDimension returns the dimension of the embedding vectors generated by the agent's model
func (*BaseAgent) GetLastRequestRawJSON ¶ added in v1.1.2
func (*BaseAgent) GetLastRequestSON ¶ added in v1.1.2
func (*BaseAgent) GetLastResponseJSON ¶ added in v1.1.2
func (*BaseAgent) GetLastResponseRawJSON ¶ added in v1.1.2
func (*BaseAgent) SaveLastEmbeddingRequest ¶ added in v1.1.2
SaveLastEmbeddingRequest saves the last embedding request JSON for logging/debugging purposes
func (*BaseAgent) SaveLastEmbeddingResponse ¶ added in v1.1.2
func (agent *BaseAgent) SaveLastEmbeddingResponse(embeddingResponse *openai.CreateEmbeddingResponse) error
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.
func (*BaseAgent) SetContext ¶ added in v1.2.2
SetContext updates the agent's context
type RagAgentOption ¶ added in v1.2.9
type RagAgentOption func(*Agent)
RagAgentOption is a functional option for configuring an Agent during creation
func AfterCompletion ¶ added in v1.2.9
func AfterCompletion(fn func(*Agent)) RagAgentOption
AfterCompletion sets a hook that is called after each embedding generation
func BeforeCompletion ¶ added in v1.2.9
func BeforeCompletion(fn func(*Agent)) RagAgentOption
BeforeCompletion sets a hook that is called before each embedding generation