Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

5.1 KB
Raw Blame

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.ā€
These sentences get mapped to similar vectors, letting your AI recognize their meaning, regardless of wording.

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 EmbeddingModelType

openai_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.