Add Watson X Integration with Granite Models #927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for IBM Watson X AI with Granite models as an alternative LLM backend to Ollama. Users can now choose between running models locally with Ollama or using IBM's hosted Granite models via Watson X.
Changes Made
New Files
rag_system/utils/watsonx_client.py: New Watson X client class that provides an Ollama-compatible interface for seamless integrationWATSONX_README.md: Comprehensive documentation for Watson X setup and usageenv.example.watsonx: Example environment configuration fileModified Files
rag_system/main.py:LLM_BACKENDconfiguration variableWATSONX_CONFIGdictionary with Watson X settingsget_agent()to support backend switchingrag_system/factory.py:get_agent()andget_indexing_pipeline()to initialize appropriate client based onLLM_BACKENDrag_system/requirements.txt:ibm-watsonx-ai>=1.3.39dependencyKey Features
✅ Backend Switching: Simple environment variable (
LLM_BACKEND=watsonx) to switch between Ollama and Watson X✅ Ollama-Compatible Interface:
WatsonXClientprovides the same API asOllamaClient✅ Granite Model Support: Works with all IBM Granite models (chat, instruct, code, multilingual)
✅ Full Feature Support: Text generation, async generation, streaming, embeddings
✅ Comprehensive Documentation: Step-by-step setup guide and troubleshooting
✅ Zero Breaking Changes: Existing Ollama functionality remains unchanged
Configuration
Users can enable Watson X by setting environment variables:
See
WATSONX_README.mdfor detailed setup instructions.Supported Granite Models
ibm/granite-13b-chat-v2- General purpose chat modelibm/granite-13b-instruct-v2- Instruction-following modelibm/granite-20b-multilingual- Multilingual supportibm/granite-8b-japanese- Lightweight modelibm/granite-3b-code-instruct- Code generationTesting
The implementation has been designed to be drop-in compatible with the existing Ollama client interface, requiring no changes to the agent, pipelines, or other components.
Benefits
Backward Compatibility
✅ All existing Ollama functionality is preserved
✅ Default backend remains Ollama
✅ No changes required for current users
✅ Watson X is opt-in via configuration
Link to Devin run: https://app.devin.ai/sessions/047e10665d1d44268b5b3325d5dc241c
Requested by: Prompt Engineering (engineerprompt@gmail.com) / @PromtEngineer
cc: @PromtEngineer