CrewAI Embeddings (original) (raw)
Last Updated : 1 May, 2026
Embeddings represent text as vectors in a high dimensional space, placing similar meanings closer together. In CrewAI, they enable memory, helping agents retain context and recall past interactions.
- Convert text into high dimensional vector representations.
- Capture semantic similarity (e.g., “cat” and “kitten” are close).
- Enable agents to store and retrieve context through memory.
- Help connect past interactions with current tasks for better responses.
Role of Embeddings in CrewAI
Embeddings play a key role in enabling intelligent memory and information handling in CrewAI systems.
- Support contextual memory by helping agents recall relevant past information.
- Enable information retrieval through similarity based search.
- Allow cross session recall by storing embeddings in databases like ChromaDB.
- Ensure continuity, preventing agents from treating each interaction independently.
Implementation
This example shows how embeddings in CrewAI enable agents to store, retrieve and share context, with memory=True ensuring continuity across tasks.
- **Agent: Defines the role, goal and backstory of an AI agent.
- **Task: Specifies the task description, assigned agent and expected output.
- **Context: Connects tasks so outputs from one task can be used in another. Python `
import os os.environ["OPENAI_API_KEY"] = "Your_API_Key"
from crewai import Agent, Task, Crew, Process
agent1 = Agent(role="Researcher", goal="Research AI history", backstory="An academic researcher.", verbose=True)
agent2 = Agent(role="Writer", goal="Write a summary", backstory="A science writer.", verbose=True)
task1 = Task(description="Collect facts about AI history.", agent=agent1, expected_output="A list of historical facts about AI.")
task2 = Task(description="Summarize the research into a short article.", agent=agent2, expected_output="A short article summarizing AI history.", context=[task1])
`
1. Using OpenAI Embeddings
OpenAI embeddings can be used for memory, offering strong semantic similarity performance. Models like text-embedding-3-small are efficient, while larger variants provide higher accuracy.
- **memory=True: Enables memory for the crew.
- **embedder: Specifies the embedding provider and model. Python `
crew = Crew( agents=[agent1, agent2], tasks=[task1, task2], process=Process.sequential, memory=True, embedder={ "provider": "openai", "config": {"model": "text-embedding-3-small"} } )
crew.kickoff()
`
**Output:

Using OpenAI Embeddings
2. Using Google Embeddings
Google embeddings are suitable for multilingual tasks and large-scale data. Models such as models/embedding-001 provide strong cross-lingual support.
- **provider="google" tells CrewAI to use Google embeddings.
- **api_key is required to authenticate with Google’s API. Python `
crew = Crew( agents=[agent1, agent2], tasks=[task1, task2], process=Process.sequential, memory=True, embedder={ "provider": "google", "config": { "model": "models/embedding-001", "api_key": "YOUR_GOOGLE_API_KEY" } } )
crew.kickoff()
`
**Output:

Using Google Embeddings
3. Using Hugging Face Embeddings
Hugging Face embeddings give access to a wide range of open-source models. Options like sentence-transformers/all-MiniLM-L6-v2 are lightweight and effective for semantic search and retrieval.
Python `
crew = Crew( agents=[agent1, agent2], tasks=[task1, task2], process=Process.sequential, memory=True, embedder={ "provider": "huggingface", "config": { "model": "sentence-transformers/all-MiniLM-L6-v2", "api_key": "YOUR_HF_API_KEY" } } )
crew.kickoff()
`
**Output:

Using Hugging Face Embeddings
4. Using Cohere Embeddings
Cohere embeddings are designed for English text and high-performance retrieval tasks. Models like embed-english-v2.0 perform well in semantic similarity and large-scale search.
Python `
import cohere
crew = Crew( agents=[agent1, agent2], tasks=[task1, task2], process=Process.sequential, memory=True, embedder={ "provider": "cohere", "config": { "model": "embed-english-v2.0", "api_key": "YOUR_COHERE_API_KEY" } } )
crew.kickoff()
`
**Output:

Using Cohere Embeddings
Comparison of Embedding Providers in CrewAI
This table outlines the main embedding providers available in CrewAI, showing how they differ in models, strengths and use cases.
| Provider | Typical Models | Strengths | Best For |
|---|---|---|---|
| **OpenAI | text-embedding-3-small, text-embedding-3-large | High-quality semantic similarity, reliable performance | General-purpose apps, balanced cost and quality |
| models/embedding-001 | Strong multilingual support, trained on large datasets | Multilingual tasks, global content, Google ecosystem | |
| **Hugging Face | sentence-transformers/all-MiniLM-L6-v2 (and others) | Open-source, flexible, customizable, cost-friendly | Research, experimentation, self-hosted setups |
| **Cohere | embed-english-v2.0 | Optimized for English, high performance in semantic search | English focused applications, production retrieval |