DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Methods / set_rag_config()
Method RAG

set_rag_config(): Reference Guide

By DevShelfHub

Sets the global RAG configuration (embedder, vector store, client options).

See the CrewAI methods catalog, CrewAI introduction, kickoff() reference, and core concepts for surrounding context.

What is set_rag_config()?

CrewAI centralizes retrieval settings behind a single global RAG client: set_rag_config(config) swaps the embedder, vector database implementation, authentication headers, and batching defaults that knowledge sources, RagTool, and internal helpers reuse. That global design keeps call sites simple — agents do not pass connection strings on every query — but it also means the call order matters: configure before you construct crews that eagerly open clients, and never re-enter set_rag_config from per-request middleware unless you enjoy thrashing indexes under load.

Pick a backend config object that matches your deployment topology: embedded Chroma for laptops, Qdrant with persistent volumes for shared staging, managed services with API keys for production. Align embedding dimensions between the model you configure and any precomputed vectors you import, or similarity search silently degrades.

In automated tests call clear_rag_config() during teardown (or set_rag_config to an in-memory backend) so suites do not leak global state into one another — the same pattern Redis or logging handlers use.

Use Cases

  • Switch vector DB
  • Configure embeddings globally

Key Features

  • Global config
  • Backend-agnostic

When NOT to Use

Per-request configuration — wrap your own factory instead.

Notes

Global singleton semantics

Anything that mutates the client mid-flight can race with concurrent kickoffs. Treat set_rag_config like wiring DATABASE_URL at boot — not something you toggle per HTTP request.

Embedding model churn

Changing embedders invalidates previously stored vectors unless you reindex. Version your config alongside migration scripts when you bump embedding models.

Secrets in config objects

API keys for hosted vector services belong in environment-backed settings, not committed YAML. Construct configs from os.environ inside your startup hook.

Relationship to get_rag_client()

After set_rag_config, advanced code can call get_rag_client() for bulk imports or admin tasks. Routine agent retrieval should still flow through knowledge sources so prompts stay portable.

Parameters

Parameter Type Required Purpose
config RAGConfig No Backend-specific config object.

Code Examples

Qdrant

python
set_rag_config(QdrantConfig(path='/data/qdrant'))

Confirm the global client after configuration

python
from crewai.rag.config.utils import set_rag_config, get_rag_client

set_rag_config(QdrantConfig(path='/data/qdrant'))
client = get_rag_client()
print(type(client))

Pytest teardown clears global state

python
import pytest
from crewai.rag.config.utils import clear_rag_config

@pytest.fixture(autouse=True)
def _reset_rag():
    yield
    clear_rag_config()

When to Use

Application setup — exactly once.

Common Mistakes

❌ Calling per-request and creating a thrash

✅ Configure once at startup.

Related: @tool decorator reference, Agent class reference, and the first Crew tutorial.

set_rag_config() FAQ

What is set_rag_config() in CrewAI?

Sets the global RAG configuration (embedder, vector store, client options). CrewAI centralizes retrieval settings behind a single global RAG client: set_rag_config(config) swaps the embedder, vector database implementation, authentication headers, and batching defaults that knowledge sources, RagTool, and internal helpers reuse. That global design keeps call sites simple — agents do not pass connection strings on every query — but it also means the call order matters: configure before you construct crews that eagerly open clients, and never re-enter …

Which CrewAI types expose the method set_rag_config()?

DevShelfHub documents set_rag_config() on RAG. The reference maps it to Python module crewai.rag.config.utils — pin your installed crewai version and match imports to the snippet on this page.

When should I use set_rag_config()?

Application setup — exactly once.

When should I avoid set_rag_config()?

Per-request configuration — wrap your own factory instead.

How do I call set_rag_config() from Python?

set_rag_config(MyConfig(...))

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.