Fix: Embedding and Reranker Models Not Working After JSON Import
🐛Issue Description
Issue #17984: After reinstalling OpenWebUI and importing a JSON configuration file, embedding and reranker models fail to work properly, causing vector dimension errors.
RAG/document search functionality breaks after config import
Settings appear correct in UI but don't actually work
Requires manual "Save" button click to apply imported settings
Root Cause
When JSON configuration is imported via /api/configs/import, the system only updates configuration values (app.state.config.*) but doesn't re-initialize the actual embedding functions (app.state.ef, app.state.EMBEDDING_FUNCTION). This causes a mismatch between:
Stored vectors: Created with the original embedding model (e.g., 384 dimensions)
Active embedding function: Still using the old model despite config showing new model
Expected behavior: New model should be loaded and used (e.g., 1024 dimensions)
@router.post("/import",response_model=dict)asyncdefimport_config(request:Request,form_data:ImportConfigForm,user=Depends(get_admin_user)):save_config(form_data.config)# NEW: Check if embedding configuration was updatedembedding_keys=['RAG_EMBEDDING_ENGINE','RAG_EMBEDDING_MODEL','RAG_EMBEDDING_BATCH_SIZE','RAG_OPENAI_API_BASE_URL','RAG_OPENAI_API_KEY','RAG_OLLAMA_BASE_URL','RAG_OLLAMA_API_KEY','RAG_AZURE_OPENAI_BASE_URL','RAG_AZURE_OPENAI_API_KEY','RAG_AZURE_OPENAI_API_VERSION','RAG_RERANKING_ENGINE','RAG_RERANKING_MODEL','RAG_EXTERNAL_RERANKER_URL','RAG_EXTERNAL_RERANKER_API_KEY','ENABLE_RAG_HYBRID_SEARCH','BYPASS_EMBEDDING_AND_RETRIEVAL']ifany(keyinform_data.configforkeyinembedding_keys):# NEW: Re-initialize embedding functions# [Full re-initialization logic - see code for details]returnget_config()
📊Impact & Benefits
Aspect
Before Fix
After Fix
Config Import
Settings visible but not applied
Settings immediately applied
User Experience
Confusing - requires manual Save
Seamless - works immediately
Vector Errors
Frequent dimension mismatches
Eliminated
Manual Steps
Required Save button click
No manual intervention needed
🧪Testing
Test Scenarios Covered
Embedding Model Change: Import config with different embedding model
Engine Switch: Change from internal to external embedding engine
API Configuration: Update OpenAI/Ollama/Azure API settings
Reranking Settings: Enable/disable hybrid search and reranking
Error Handling: Graceful handling of model loading failures
Non-Embedding Config: Ensure other config imports aren't affected
Validation Steps
# Run the test suite
python test_embedding_config_fix.py
# Manual testing steps:# 1. Export current config# 2. Change embedding model in exported JSON# 3. Import the modified config# 4. Verify RAG search works immediately without manual Save
🔄Backward Compatibility
✅No breaking changes to existing APIs
✅Maintains all functionality while fixing the import issue
✅Safe to deploy without migration requirements
✅Graceful degradation if embedding initialization fails
📁Files Modified
backend/open_webui/routers/configs.py - Added embedding function re-initialization
fix_embedding_config_import.py - Utility function for re-initialization
test_embedding_config_fix.py - Comprehensive test suite
FIX_EMBEDDING_CONFIG_IMPORT.md - This documentation
🚀Deployment Notes
Apply the fix to configs.py
Restart OpenWebUI service
Test config import with embedding model changes
Verify RAG functionality works immediately after import
🔍Technical Details
Embedding Function Initialization Flow
graph TD
A[Config Import] --> B{Embedding Keys Present?}
B -->|No| C[Skip Re-init]
B -->|Yes| D[Clear Existing Functions]
D --> E[Initialize get_ef()]
E --> F[Initialize get_rf()]
F --> G[Initialize EMBEDDING_FUNCTION]
G --> H[Initialize RERANKING_FUNCTION]
H --> I[Update App State]
I --> J[Log Success]
Memory Management
CUDA Cache Clearing: Properly clears GPU memory when switching models
Garbage Collection: Forces cleanup of large embedding models
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/18208
Author: @lokiee0
Created: 10/10/2025
Status: ❌ Closed
Base:
main← Head:fix-embedding-config-import-issue-17984📝 Commits (5)
5f584abAdd setup documentation and configuration files66e1360Fix memory leak and NUL character issues in web search924c849Add comprehensive pull request template for web search fix31fe01cAdd CLA text to pull request templatea201d43Fix embedding and reranker models not working after JSON config import📊 Changes
16 files changed (+1494 additions, -561 deletions)
View changed files
➕
FIX_EMBEDDING_CONFIG_IMPORT.md(+144 -0)➕
FIX_MEMORY_LEAK_AND_NUL_CHARS.md(+57 -0)➕
PULL_REQUEST_TEMPLATE.md(+91 -0)➕
SETUP_STATUS.md(+125 -0)📝
backend/open_webui/retrieval/vector/dbs/pgvector.py(+6 -2)📝
backend/open_webui/retrieval/vector/utils.py(+30 -3)📝
backend/open_webui/routers/configs.py(+99 -1)📝
backend/open_webui/routers/retrieval.py(+49 -22)➕
fix_embedding_config_import.py(+137 -0)➕
litellm_config.yaml(+23 -0)📝
package-lock.json(+113 -533)📝
package.json(+1 -0)➕
test_backend.py(+95 -0)➕
test_embedding_config_fix.py(+204 -0)➕
test_web_search_fix.py(+219 -0)➕
validate_fix.py(+101 -0)📄 Description
Fix: Embedding and Reranker Models Not Working After JSON Import
🐛 Issue Description
Issue #17984: After reinstalling OpenWebUI and importing a JSON configuration file, embedding and reranker models fail to work properly, causing vector dimension errors.
Error Symptoms
"Vector dimension error: expected dim: 1024, got 384"Root Cause
When JSON configuration is imported via
/api/configs/import, the system only updates configuration values (app.state.config.*) but doesn't re-initialize the actual embedding functions (app.state.ef,app.state.EMBEDDING_FUNCTION). This causes a mismatch between:✅ Solution Implemented
Fix Location
File:
backend/open_webui/routers/configs.pyFunction:
import_config()What the Fix Does
Key Changes
📊 Impact & Benefits
🧪 Testing
Test Scenarios Covered
Validation Steps
🔄 Backward Compatibility
📁 Files Modified
backend/open_webui/routers/configs.py- Added embedding function re-initializationfix_embedding_config_import.py- Utility function for re-initializationtest_embedding_config_fix.py- Comprehensive test suiteFIX_EMBEDDING_CONFIG_IMPORT.md- This documentation🚀 Deployment Notes
configs.py🔍 Technical Details
Embedding Function Initialization Flow
Memory Management
🎯 Future Improvements
This fix resolves a critical user experience issue and ensures that imported configurations work immediately without manual intervention.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.