[go: up one dir, main page]

rig

Module embeddings

source
Expand description

This module provides functionality for working with embeddings and embedding models. Embeddings are numerical representations of documents or other objects, typically used in natural language processing (NLP) tasks such as text classification, information retrieval, and document similarity.

The module defines the EmbeddingModel trait, which represents an embedding model that can generate embeddings for documents. It also provides an implementation of the EmbeddingsBuilder struct, which allows users to build collections of document embeddings using different embedding models and document sources.

The module also defines the Embedding struct, which represents a single document embedding, and the DocumentEmbeddings struct, which represents a document along with its associated embeddings. These structs are used to store and manipulate collections of document embeddings.

Finally, the module defines the EmbeddingError enum, which represents various errors that can occur during embedding generation or processing.

§Example

use rig::providers::openai::{Client, self};
use rig::embeddings::{EmbeddingModel, EmbeddingsBuilder};

// Initialize the OpenAI client
let openai = Client::new("your-openai-api-key");

// Create an instance of the `text-embedding-ada-002` model
let embedding_model = openai.embedding_model(openai::TEXT_EMBEDDING_ADA_002);

// Create an embeddings builder and add documents
let embeddings = EmbeddingsBuilder::new(embedding_model)
    .simple_document("doc1", "This is the first document.")                                                                                                         
    .simple_document("doc2", "This is the second document.")
    .build()
    .await
    .expect("Failed to build embeddings.");
                                 
// Use the generated embeddings
// ...

Structs§

Enums§

Traits§

  • Trait for embedding models that can generate embeddings for documents.