Integration with Third-Party Platforms
Integrate RAG knowledge bases with Dify, Coze, n8n, LangChain, and other platforms
Dify
Dify supports integration via External Knowledge sources.
-
Obtain API Information
In the Bailian console, go to the Service Channels page and copy the DashScope API Endpoint and API Key.
-
Configure Dify
In Dify's Knowledge Base settings, select External Knowledge, then fill in:
- API Endpoint: DashScope retrieval endpoint URL
- API Key: Your DashScope API Key
- Knowledge Base ID: Target knowledge base ID
-
Use in Workflows
In Dify workflows or chat applications, select this external knowledge base as the retrieval source.
Coze
Coze supports integration via MCP or custom API plugins.
Method 1: MCP Integration
Add an MCP tool in Coze Bot settings:
- Select Add MCP Tool
- Enter the MCP Server URL and authentication details (obtained from the Service Channels page in the console)
- Select the retrieval / Q&A capabilities to expose
Method 2: API Plugin
- Create a custom plugin in Coze
- Configure an HTTP request pointing to the DashScope retrieval endpoint
- Map input parameters (
query,top_k) and output parameters (list of chunks)
n8n
n8n can call the Knowledge (formerly RAG) retrieval API using the HTTP Request node:
- Add an HTTP Request node
- Set method to POST and enter the retrieval endpoint URL (see details below)
- In Headers, add
Authorization: Bearer <API-Key> - Fill in retrieval parameters in the Body
Two endpoints are available:
- Knowledge Search (application-level, recommended):
https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/knowledge/search. Parameters:queryandagent_id; retrieval strategy is driven by the knowledge retrieval service configuration. - Low-Level Retrieval:
https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/rag/index/retrieve. Parameters:index_id,query,top_k; directly specifies the knowledge base ID.
LangChain
Use as a custom Retriever in LangChain:
import requests
class DashScopeRetriever:
def __init__(self, api_key, index_id):
self.api_key = api_key
self.index_id = index_id
def get_relevant_documents(self, query):
resp = requests.post(
"https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/rag/index/retrieve",
headers={
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
},
json={
"index_id": self.index_id,
"query": query,
"top_k": 5,
},
)
nodes = resp.json().get("data", {}).get("nodes", [])
return [{"page_content": n["text"], "metadata": n.get("metadata", {})} for n in nodes]
NoteThe above code is for illustration only. When using in production, add proper error handling and retry logic.
ImportantAll third-party integrations rely on the DashScope API. For full API documentation, see the API Reference.