š« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
title: "Embeddings" icon: vector-square
doc_code_map: - "camel/embeddings/**/*.py"
Embeddings transform text, images, and other media into dense numeric vectors that capture their underlying meaning. This makes it possible for machines to perform semantic search, similarity, recommendations, clustering, RAG, and more. Text embeddings turn sentences or documents into high-dimensional vectors that capture meaning. Example:- āA young boy is playing soccer in a park.ā
- āA child is kicking a football on a playground.ā
Image embeddings use neural networks (like CNNs) or vision-language models to turn images into numeric vectors, capturing shapes, colors, and features. For example: A cat image ā vector that is ācloseā to other cats and āfarā from cars in vector space.
Supported Embedding Types
Use OpenAIās API to generate text embeddings.Requires: OpenAI API Key. Use Mistralās API for text embeddings.
Requires: Mistral API Key. Local, open-source transformer models from the{" "} Sentence Transformers {" "} library. OpenAIās vision models for image embeddings.
Requires: OpenAI API Key. Text embeddings from OpenAI models on Azure.
Requires: Azure OpenAI API Key. Together AIās hosted models for text embeddings.
Requires: Together AI API Key.
Usage Examples
Make sure you have the right API key set (OpenAI, Mistral, Azure, or Together) for the embedding backend you want to use. ```python openai_embed.py from camel.embeddings import OpenAIEmbedding from camel.types import EmbeddingModelTypeopenai_embedding = OpenAIEmbedding(model_type=EmbeddingModelType.TEXT_EMBEDDING_3_SMALL) embeddings = openai_embedding.embed_list(["Hello, world!", "Another example"])
</CodeGroup>
</Card>
<Card title="Text Embeddings with Mistral" icon="wind">
<CodeGroup>
```python mistral_embed.py
from camel.embeddings import MistralEmbedding
from camel.types import EmbeddingModelType
mistral_embedding = MistralEmbedding(model_type=EmbeddingModelType.MISTRAL_EMBED)
embeddings = mistral_embedding.embed_list(["Hello, world!", "Another example"])
```python sentence_transformer_embed.py
from camel.embeddings import SentenceTransformerEncoder
sentence_encoder = SentenceTransformerEncoder(model_name='intfloat/e5-large-v2') embeddings = sentence_encoder.embed_list(["Hello, world!", "Another example"])
</CodeGroup>
</Card>
<Card title="Image Embeddings with Vision-Language Models" icon="image">
<CodeGroup>
```python image_embed.py
from camel.embeddings import VisionLanguageEmbedding
from PIL import Image
import requests
vlm_embedding = VisionLanguageEmbedding()
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
test_images = [image, image]
embeddings = vlm_embedding.embed_list(test_images)
```python azure_embed.py
from camel.embeddings import AzureEmbedding
from camel.types import EmbeddingModelType
azure_openai_embedding = AzureEmbedding(model_type=EmbeddingModelType.TEXT_EMBEDDING_ADA_2) embeddings = azure_openai_embedding.embed_list(["Hello, world!", "Another example"])
</CodeGroup>
</Card>
<Card title="Text Embeddings with Together AI" icon="users">
<CodeGroup>
```python together_embed.py
from camel.embeddings import TogetherEmbedding
together_embedding = TogetherEmbedding(model_type="togethercomputer/m2-bert-80M-8k-retrieval")
embeddings = together_embedding.embed_list(["Hello, world!", "Another example"])
Pick a text embedding that matches your language, latency, and privacy needs.
For multimodal use cases, use image or vision-language embeddings.
Explore retrieval-augmented generation (RAG) and search recipes using
embeddings.
Full API docs and all configuration options.