View Source Rag.Embedding (rag v0.2.1)

Functions to generate embeddings.

Summary

Functions

Passes generation.query to embeddings_function or provider to generate an embedding. Then, puts the embedding in generation.query_embedding.

Passes a text from ingestion to embeddings_function or provider to generate an embedding. Then, puts the embedding in ingestion.

Passes all values of ingestions at text_key to embeddings_function or provider to generate all embeddings in a single batch. Puts the embeddings in ingestions at embedding_key.

Types

embedding()

@type embedding() :: [number()]

embeddings_function()

@type embeddings_function() :: ([String.t()], keyword() -> [embedding()])

provider()

@type provider() :: struct()

Functions

generate_embedding(generation, provider)

@spec generate_embedding(Rag.Generation.t(), embeddings_function() | provider()) ::
  Rag.Generation.t()

Passes generation.query to embeddings_function or provider to generate an embedding. Then, puts the embedding in generation.query_embedding.

generate_embedding(ingestion, provider, opts)

@spec generate_embedding(map(), embeddings_function() | provider(), opts :: keyword()) ::
  %{
    required(atom()) => embedding(),
    optional(any()) => any()
  }

Passes a text from ingestion to embeddings_function or provider to generate an embedding. Then, puts the embedding in ingestion.

Options

  • text_key: key which holds the text that is used to generate the embedding. Default: :text
  • embedding_key: key where the generated embedding is stored. Default: :embedding

generate_embeddings_batch(ingestions, provider, opts)

@spec generate_embeddings_batch(
  [map()],
  embeddings_function() | provider(),
  opts :: keyword()
) :: [%{required(atom()) => embedding(), optional(any()) => any()}]

Passes all values of ingestions at text_key to embeddings_function or provider to generate all embeddings in a single batch. Puts the embeddings in ingestions at embedding_key.

Options

  • text_key: key which holds the text that is used to generate the embedding. Default: :text
  • embedding_key: key where the generated embedding is stored. Default: :embedding