Embedding v1.2

Overview

Embeddings in Gen AI Builder are multidimensional representations of text or image data. Embeddings carry semantic information, making them powerful for use-cases like text or image similarity search in a Rag Engine.

Embedding Drivers

OpenAI

The OpenAiEmbeddingDriver uses the OpenAI Embeddings API.

[0.0017853748286142945, 0.006118456833064556, -0.005811543669551611]

OpenAI Compatible

Many services such as LMStudio and OhMyGPT provide OpenAI-compatible APIs. You can use the OpenAiEmbeddingDriver to interact with these services. Simply set the base_url to the service's API endpoint and the model to the model name. If the service requires an API key, you can set it in the api_key field.

from griptape.drivers.embedding.openai import OpenAiEmbeddingDriver

embedding_driver = OpenAiEmbeddingDriver(
    base_url="http://127.0.0.1:1234/v1",
    model="nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.Q2_K",
)

embeddings = embedding_driver.embed("Hello world!")

# display the first 3 embeddings
print(embeddings[:3])
Tip

Make sure to include v1 at the end of the base_url to match the OpenAI API endpoint.

Azure OpenAI

The AzureOpenAiEmbeddingDriver uses the same parameters as OpenAiEmbeddingDriver with updated defaults.

Bedrock Titan

Info

This driver requires the drivers-embedding-amazon-bedrock extra.

The AmazonBedrockTitanEmbeddingDriver uses the Amazon Bedrock Embeddings API.

[-0.234375, -0.024902344, -0.14941406]

Google

Info

This driver requires the drivers-embedding-google extra.

The GoogleEmbeddingDriver uses the Google Embeddings API.

[0.0588633, 0.0033929371, -0.072810836]

Hugging Face Hub

Info

This driver requires the drivers-embedding-huggingface extra.

The HuggingFaceHubEmbeddingDriver connects to the Hugging Face Hub API. It supports models with the following tasks:

  • feature-extraction

Ollama

Info

This driver requires the drivers-embedding-ollama extra.

The OllamaEmbeddingDriver uses the Ollama Embeddings API.

from griptape.drivers.embedding.ollama import OllamaEmbeddingDriver

driver = OllamaEmbeddingDriver(
    model="all-minilm",
)

results = driver.embed("Hello world!")

# display the first 3 embeddings
print(results[:3])

Amazon SageMaker Jumpstart

The AmazonSageMakerJumpstartEmbeddingDriver uses the Amazon SageMaker Endpoints to generate embeddings on AWS.

Info

This driver requires the drivers-embedding-amazon-sagemaker extra.

import os

from griptape.drivers.embedding.amazon_sagemaker_jumpstart import AmazonSageMakerJumpstartEmbeddingDriver

driver = AmazonSageMakerJumpstartEmbeddingDriver(
    endpoint=os.environ["SAGEMAKER_ENDPOINT"],
    model=os.environ["SAGEMAKER_TENSORFLOW_HUB_MODEL"],
)

embeddings = driver.embed("Hello world!")

# display the first 3 embeddings
print(embeddings[:3])

VoyageAI

The VoyageAiEmbeddingDriver uses the VoyageAI Embeddings API.

Info

This driver requires the drivers-embedding-voyageai extra.

Cohere

The CohereEmbeddingDriver uses the Cohere Embeddings API.

Info

This driver requires the drivers-embedding-cohere extra.

Nvidia NIM

The NvidiaNimEmbeddingDriver uses the Nvidia NIM API.

Info

The Nvidia NIM API is OpenAI compatible, except for a single parameter: input_type. This parameter is controlled by the keyword argument vector_operation when calling the driver embed methods.

Override Default Structure Embedding Driver

Here is how you can override the Embedding Driver that is used by default in Structures.