Managing Knowledge in CrewAI
In CrewAI, Knowledge is how you give agents access to external information (files, web content, structured data) in a reusable, searchable way. You can think of it as a vectorized reference library that sits beside your agents and crews, powering retrieval‑augmented generation (RAG).
1. What “Knowledge” Means in CrewAI
Knowledge lets agents:
- Use domain‑specific information instead of relying only on the base LLM.
- Support decisions with grounded, real‑world data.
- Maintain context across tasks and conversations.
- Reduce hallucinations by retrieving relevant chunks from your own sources.
Under the hood, CrewAI embeds your content into a vector store (ChromaDB by default) and queries it when tasks run.
2. Quickstart: Basic Knowledge Examples
2.1 String knowledge (simple, in‑memory)
The agent answers from the knowledge store, not just its prior training.
2.2 Web content knowledge
CrewDoclingSource ingests and chunks remote documents; queries run over that embedded content.
3. Supported Knowledge Sources
CrewAI ships multiple knowledge adapters so you can plug in different file types.
All files are usually placed in a ./knowledge folder in your project root for convenience.
3.1 Text sources
- Raw string content – StringKnowledgeSource
- Text files (.txt) – TextFileKnowledgeSource
3.2 PDF
3.3 Structured data: CSV, Excel, JSON
You can combine multiple sources in a single crew or agent.
4. Agent‑Level vs Crew‑Level Knowledge
Knowledge can live at agent level or crew level, and both can coexist.
4.1 Agent‑only knowledge (independent)
The agent uses its own knowledge even if the crew has none configured.
4.2 Crew‑wide + agent‑specific
Result
- Specialist sees: crew_knowledge + specialist_knowledge.
- Generalist sees: crew_knowledge only.
4.3 Multiple agents with different knowledge + embedders
You can give each agent its own knowledge + embedding provider, with a crew‑level fallback.
Each agent gets only its own knowledge and can use a different embedding stack.
5. Knowledge Configuration and Storage
5.1 KnowledgeConfig: controlling retrieval
You can tune how much and how strict knowledge retrieval is.
Core parameters include:
- results_limit – max number of chunks returned per query.
- score_threshold – minimum similarity score.
- Other fields (e.g., collection names, storage config) via KnowledgeStorage.
5.2 Where knowledge is stored (ChromaDB)
By default, CrewAI stores knowledge in a ChromaDB directory under a platform‑specific path.
- macOS:
- Linux:
- Windows:
Each collection has its own folder; agent and crew collections are separate.
You can inspect the path with:
5.3 Controlling storage location
Option 1: Environment variable (recommended)
Option 2: Custom KnowledgeStorage
Option 3: Project‑local directory
6. Embedding Providers for Knowledge
By default, knowledge embeddings use OpenAI text-embedding-3-small, even if your LLM is from another provider.
You can override this at crew or agent level.
6.1 Matching embeddings to your stack
Example – Voyage AI with Claude:
Local embeddings (no external API):
Agent‑level override (e.g., Gemini embeddings):
Azure OpenAI embeddings:
7. Advanced Features: Query Rewriting, Events, and Custom Sources
7.1 Query rewriting (better retrieval)
CrewAI automatically rewrites queries to improve retrieval quality.
- When a task uses knowledge, getknowledge_search_query runs.
- The agent’s LLM turns the full task prompt into a concise search query.
Example transformation:
This improves recall and relevance in vector search.
7.2 Knowledge events (observability)
CrewAI emits events around knowledge retrieval, e.g.:
KnowledgeRetrievalStartedEventKnowledgeRetrievalCompletedEventKnowledgeQueryStartedEvent / CompletedEvent / FailedEvent
You can subscribe using the event bus to monitor how knowledge is used.
7.3 Custom knowledge sources
You can build your own subclasses of BaseKnowledgeSource for any API or data source.
Example: SpaceNewsKnowledgeSource that fetches from a space‑news API, chunks articles, and stores them as knowledge, then used by a Space News Analyst agent to answer questions about current space events.
8. Debugging and Resetting Knowledge
8.1 Debugging tips
- Check initialization:
- Verify storage location and contents using db_storage_path() and listing the knowledge folder.
- Use ChromaDB’s client to inspect collections and sample documents.
8.2 Resetting knowledge
Use the crew API or CLI:
This is useful when you update documents and want a fresh embedding pass.
9. Best Practices for an Agentic Architect
Here are some key patterns:
- Use agent‑level knowledge for role‑specific “playbooks” (sales, support, tech).
- Use crew‑level knowledge for shared policies, company docs, or product info.
- Choose embedding providers explicitly, especially in production.
- Keep a dedicated
knowledge/ folder and treat it like a content repo. - Monitor storage growth and include knowledge dirs in backups and deployments.
- Reset knowledge when major content changes, and test retrieval with small queries.
Framed simply:
- Memory is what agents learn over time;
- Knowledge is the library you preload so they can answer with accurate, grounded information.