View Source Rag.Generation (rag v0.2.3)
Functions to generate a response and helpers to work with a generation struct.
Summary
Types
Represents a generation, the main datastructure in rag.
Functions
Appends an error to the existing list of errors.
Passes generation and opts to context_builder_function to determine the context.
Then, puts the context in generation.context.
Passes generation and opts to context_sources_builder_function to determine the context sources.
Then, puts the context sources in generation.context_sources.
Passes generation and opts to prompt_builder_function to determine the prompt.
Then, puts the prompt in generation.prompt.
Passes generation.prompt to response_function or provider to generate a response.
If successful, puts the result in generation.response.
Gets the evaluation at key in generation.evaluations.
Gets the retrieval result at key in generation.retrieval_results.
Sets halted? to true to skip all remaining operations.
Creates a new generation struct from a query.
Puts context in generation.context.
Puts context_sources in generation.context_sources.
Puts evaluation at key in generation.evaluations.
Puts prompt in generation.prompt.
Puts query_embedding in generation.query_embedding.
Puts response in generation.response.
Puts retrieval_result at key in generation.retrieval_results.
Types
@type embedding() :: [number()]
@type provider() :: struct()
@type response() :: String.t() | Enumerable.t()
@type t() :: %Rag.Generation{ context: String.t() | nil, context_sources: [String.t()], errors: [any()], evaluations: %{optional(atom()) => any()}, halted?: boolean(), prompt: String.t() | nil, query: String.t() | nil, query_embedding: embedding() | nil, ref: any(), response: response() | nil, retrieval_results: %{optional(atom()) => any()} }
Represents a generation, the main datastructure in rag.
Functions
Appends an error to the existing list of errors.
@spec build_context(t(), context_builder_function(), keyword()) :: t()
Passes generation and opts to context_builder_function to determine the context.
Then, puts the context in generation.context.
@spec build_context_sources(t(), context_sources_builder_function(), keyword()) :: t()
Passes generation and opts to context_sources_builder_function to determine the context sources.
Then, puts the context sources in generation.context_sources.
@spec build_prompt(t(), prompt_builder_function(), keyword()) :: t()
Passes generation and opts to prompt_builder_function to determine the prompt.
Then, puts the prompt in generation.prompt.
@spec generate_response(t(), response_function() | provider(), keyword()) :: t()
Passes generation.prompt to response_function or provider to generate a response.
If successful, puts the result in generation.response.
Gets the evaluation at key in generation.evaluations.
Gets the retrieval result at key in generation.retrieval_results.
Sets halted? to true to skip all remaining operations.
Creates a new generation struct from a query.
Puts context in generation.context.
Puts context_sources in generation.context_sources.
Puts evaluation at key in generation.evaluations.
Puts prompt in generation.prompt.
Puts query_embedding in generation.query_embedding.
Puts response in generation.response.
Puts retrieval_result at key in generation.retrieval_results.