This document details the concrete provider implementations and the factory patterns used to register and instantiate LLM providers in both the Python and Go layers of RAGFlow. It covers the dynamic discovery mechanism, registry structures, and the implementation patterns across supported AI providers.
RAGFlow uses a dynamic factory pattern that automatically discovers and registers provider implementations at module load time.
In the Python backend, the system bridges the "Natural Language Space" of provider names to the "Code Entity Space" of Python classes during initialization.
Title: Python Provider Registration Flow
Sources: rag/llm/__init__.py155-170 rag/llm/__init__.py171-187
The Go-native layer uses a central ModelFactory to instantiate ModelDriver implementations. Unlike the Python side's dynamic inspection, the Go factory uses an explicit switch-case mapping.
Title: Go Model Factory Mapping
Sources: internal/entity/models/factory.go33-165 internal/entity/models/types.go24-57
The system maintains a comprehensive list of supported models and their capabilities in JSON configuration files.
conf/llm_factories.json serves as the master list for model capabilities, including max_tokens, model_type, and is_tools flags.
| Provider Name | Model Name | Max Tokens | Model Types | Tools Support |
|---|---|---|---|---|
aimlapi.com | openai/gpt-4o | 128,000 | ["chat", "image2text"] | True |
OpenAI | gpt-5.5 | 400,000 | ["chat"] | True |
OpenAI | text-embedding-3-small | 8,191 | ["embedding"] | False |
Sources: conf/llm_factories.json3-20 conf/llm_factories.json83-96 conf/llm_factories.json315-323
Providers often require specific base URLs and prefixes, especially when using the LiteLLM backend.
https://api.deepseek.com/v1) or Moonshot (https://api.moonshot.cn/v1). rag/llm/__init__.py68-99dashscope/ for Tongyi-Qianwen. rag/llm/__init__.py102-143Providers implement task-specific logic (Chat, Embedding, Rerank, CV, TTS, ASR) to handle various AI tasks.
The ChatModel implementation handles model-specific quirks via _apply_model_family_policies.
temperature and top_p for certain reasoning models. rag/llm/chat_model.py112-200temperature, max_completion_tokens, tools, etc.) to be forwarded to underlying APIs to prevent "Unknown parameter" errors. rag/llm/chat_model.py73-96[0, 1] range for hybrid search blending. rag/llm/rerank_model.py69-93FishAudioTTS using msgpack. rag/llm/tts_model.py84-140 rag/llm/tts_model.py141-181The TenantLLMService and LLMBundle manage how specific users (tenants) interact with these factory implementations.
When a user sets an API key, the system performs a "sanity check" by attempting a small request (chat, embedding, or rerank) to verify the credentials. api/apps/llm_app.py74-150
LLMBundle acts as a high-level wrapper around the underlying model instances, handling:
Sources:
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.