What is clear_rag_config()?
clear_rag_config() tears down the process-wide RAG client that set_rag_config established. Automated suites call it so one test's Qdrant path or embedder choice does not leak into another module's assumptions about defaults. After clearing, the next set_rag_config call rebuilds clients exactly as they would on a fresh interpreter — useful when parametrizing tests across multiple vector backends.
Unlike deleting on-disk corpora, clearing config does not remove stored vectors; it only forgets connection handles and embedding settings. Pair with reset_memories or filesystem cleanup when you need a truly empty slate. In CI, prefer ephemeral directories referenced through CREWAI_STORAGE_DIR plus clear_rag_config between cases.
Production services should almost never invoke this on hot paths — a cleared client mid-request races with concurrent kickoffs. Treat it strictly as test hygiene or controlled maintenance windows.
Use Cases
- • Test isolation
Key Features
- ✓ Reset to defaults
When NOT to Use
Production.
Notes
Order with get_rag_client
Holding a stale client object after clear_rag_config is undefined behavior. Drop references or call get_rag_client again only after reconfiguring.
Thread safety
Parallel tests that mutate global RAG state need process isolation or strict locks — clears are not fine-grained mutexes.
Does not revert environment variables
CREWAI_STORAGE_DIR and provider secrets remain in os.environ. Clearing config is not a substitute for resetting env fixtures.
Version drift
Default client behavior changes across crewai releases. Document which version your fixture expects when mixing clear/set in shared conftest files.
Code Examples
Reset
clear_rag_config()
Pytest fixture with setup and teardown
import pytest
from crewai.rag.chromadb.config import ChromaDBConfig
from crewai.rag.config.utils import clear_rag_config, set_rag_config
@pytest.fixture
def rag_tmp(tmp_path):
set_rag_config(ChromaDBConfig(path=str(tmp_path / 'chroma')))
yield
clear_rag_config()
Switch backends between two tests in one file
from crewai.rag.chromadb.config import ChromaDBConfig
from crewai.rag.config.utils import clear_rag_config, set_rag_config
from crewai.rag.qdrant.config import QdrantConfig
def test_qdrant_backend():
set_rag_config(QdrantConfig(path='/tmp/q1'))
...
clear_rag_config()
def test_chroma_backend():
set_rag_config(ChromaDBConfig(path='/tmp/ch1'))
...
When to Use
Test setup/teardown.
Common Mistakes
❌ Calling clear_rag_config in production to switch tenants per request
✅ Use separate processes or dependency-injected factories instead of the global singleton.
❌ Assuming clear deletes vector files
✅ Remove data directories explicitly or use ephemeral tmp_path roots in tests.
Related: @tool decorator reference, Agent class reference, and the first Crew tutorial.
clear_rag_config() FAQ
What is clear_rag_config() in CrewAI?
Removes the global RAG configuration — used in tests for isolation. clear_rag_config() tears down the process-wide RAG client that set_rag_config established. Automated suites call it so one test's Qdrant path or embedder choice does not leak into another module's assumptions about defaults. After clearing, the next set_rag_config call rebuilds clients exactly as they would on a fresh interpreter — useful when parametrizing tests across multiple vector backends. Unlike deleting on-disk corpora, clearing config does not remove stored vectors;…
Which CrewAI types expose the method clear_rag_config()?
DevShelfHub documents clear_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 clear_rag_config()?
Test setup/teardown.
When should I avoid clear_rag_config()?
Production.
How do I call clear_rag_config() from Python?
clear_rag_config()
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.