Open In App

CrewAI Embeddings

Last Updated : 10 Oct, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Embeddings are numerical vector representations of text. Instead of treating words and sentences as raw text, they are mapped into high-dimensional vector spaces. In this space, semantically similar texts like “cat” and “kitten” are close to each other, while unrelated texts like “cat” and “rocket” are farther apart. When we work with AI agents in CrewAI, memory plays a key role in enabling agents to retain context, recall past interactions and connect related ideas. Behind the scenes, this memory system uses embeddings.

Understanding Embeddings in CrewAI

Embeddings are essential in CrewAI for:

  • Contextual Memory: Agents can recall relevant past information by comparing embeddings.
  • Information Retrieval: Queries can be matched with related knowledge using similarity search.
  • Cross-Session Recall: Long-term memory is supported by storing embeddings in databases like ChromaDB.

Without embeddings, agents would treat each interaction in isolation and lose continuity.

Implementation of Different Embeddings in CrewAI

We will implement different embedding providers in CrewAI and observe how they enable agents to store, retrieve and share contextual memory across tasks. In CrewAI, we can enable memory and configure the embedding provider. When memory=True is set in a Crew object, embeddings allow tasks and agents to share context effectively.

But before that we will first define the agents and their tasks which will later share context through embeddings.

  • Agent: Defines the role, goal and backstory of an AI agent.
  • Task: Specifies what an agent should do (description), who does it (agent) and what to expect (expected_output).
  • context: Links tasks together so outputs can flow from one to the next.
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

We will configure CrewAI to use OpenAI embeddings for memory. OpenAI embeddings are highly optimized for semantic similarity and widely supported across applications. They are a good default choice when you want reliable performance and easy integration. The text-embedding-3-small model is lightweight and cost-efficient, while larger variants (-large) provide more 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:

openAI
Using OpenAI Embeddings

Note: The embeddings we use decide how well agents understand and remember information. Changing the provider can make the output more focused on meaning, better at handling multiple languages or stronger for specific tasks.

2. Using Google Embeddings

We will switch to Google’s embedding model. Google’s embeddings (e.g., models/embedding-001) are trained on massive datasets and optimized for multilingual text. If our tasks involve global content (different languages, search, summarization), Google embeddings 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:

googleAPI
Using Google Embeddings

3. Using Hugging Face Embeddings

We will configure CrewAI to use Hugging Face embeddings. Hugging Face offers a wide range of open-source models that can be used for free or with hosted inference. Models like sentence-transformers/all-MiniLM-L6-v2 are lightweight and excellent for semantic search and retrieval. It is also a good option if we want custom or fine-tuned embeddings.

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

We will demonstrate how to use Cohere’s embeddings. Cohere’s embeddings (e.g., embed-english-v2.0) are specialized for English text and optimized for production search and retrieval tasks. They showcase high performance on semantic similarity benchmarks, especially when working with large-scale retrieval systems.

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.

ProviderTypical ModelsStrengthsBest For
OpenAItext-embedding-3-small, text-embedding-3-largeHigh-quality semantic similarity, reliable performanceGeneral-purpose apps, balanced cost and quality
Googlemodels/embedding-001Strong multilingual support, trained on large datasetsMultilingual tasks, global content, Google ecosystem
Hugging Facesentence-transformers/all-MiniLM-L6-v2 (and others)Open-source, flexible, customizable, cost-friendlyResearch, experimentation, self-hosted setups
Cohereembed-english-v2.0Optimized for English, high performance in semantic searchEnglish-focused applications, production retrieval

Explore