-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix ValidationError when using memory=True without OpenAI API key #2944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add fallback embedding providers in EmbeddingConfigurator - Modify RAGStorage and KnowledgeStorage to use fallback mechanism - Add comprehensive tests for memory functionality without OpenAI API key - Resolves issue #2943 by allowing memory=True with alternative embedding providers Fallback hierarchy: OpenAI -> Ollama -> HuggingFace -> SentenceTransformers Co-Authored-By: João <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Disclaimer: This review was made by a crew of AI Agents. Code Review Comment: Memory Fallback ImplementationOverviewThis pull request enhances the embedding functionality by introducing a robust fallback mechanism for when the OpenAI API key is unavailable. The changes focus on three core components— Detailed Insights1. Embedding Configurator ImprovementsFile: Positive Aspects:
Suggested Code Improvements:
2. Storage Mechanism EnhancementsFiles: Positive Aspects:
Suggested Code Enhancements:
3. Testing Suite EnhancementsFile: Positive Aspects:
Suggested Improvements:
General Recommendations
Security Considerations
ConclusionThe overall implementation represents a significant step forward in enhancing system robustness and user experience in scenarios where the OpenAI API may not be accessible. The suggested improvements aim to bolster the quality, maintainability, and monitoring of the new functionality, ensuring that future development continues smoothly while maintaining high standards of performance and security. For more related insights, reviewing historical PRs that dealt with embedding functionality and error handling strategies can provide valuable context and guidance. |
- Remove unused imports (os from rag_storage.py, pytest from test_memory_fallback.py) - Add specific exception handling in fallback mechanism (ConnectionError, ImportError, ValueError) - Add comprehensive logging to track embedding provider selection and fallback attempts - Resolves CI lint failures and addresses PR review feedback Co-Authored-By: João <[email protected]>
Closing due to inactivity for more than 7 days. |
Fix ValidationError when using memory=True without OpenAI API key
Description
This PR resolves issue #2943 where CrewAI throws a ValidationError when
memory=True
is set but no OpenAI API key is provided. The issue occurred because the memory system hardcoded OpenAI embeddings as the default, but should gracefully fallback to alternative embedding providers when OpenAI API key is unavailable.Root Cause
The ValidationError was triggered during Crew initialization when
memory=True
caused ShortTermMemory and EntityMemory to create RAGStorage instances. These storage classes used_create_default_embedding_function()
which directly called ChromaDB's OpenAI embedding function without an API key, causing the validation error.Solution
EmbeddingConfigurator
to includecreate_default_embedding_with_fallback()
methodRAGStorage
andKnowledgeStorage
to use the fallback mechanism when no embedder config is providedChanges Made
create_default_embedding_with_fallback()
method with graceful fallback providers_set_embedder_config()
to use fallback when embedder_config is None_create_default_embedding_function()
to use fallback mechanismTesting
Verification
Link to Devin run
https://app.devin.ai/sessions/aa78e5a54dc248479d5899811afe2d57
Requested by
João ([email protected])
Fixes #2943