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.

Role of Embeddings in CrewAI

Embeddings play a key role in enabling intelligent memory and information handling in CrewAI systems.

Implementation

This example shows how embeddings in CrewAI enable agents to store, retrieve and share context, with memory=True ensuring continuity across tasks.

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.

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:

openAI

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.

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:

googleAPI

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:

huggingfaceAPI

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:

cohereAPI

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
**Google 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