Skip to main content
Integration

Integration with Third-Party Platforms

Integrate RAG knowledge bases with Dify, Coze, n8n, LangChain, and other platforms

RAG knowledge bases provide standard APIs and the MCP protocol to integrate with mainstream AI application development platforms.

Dify

Dify supports integration via External Knowledge sources.
1

Obtain API Information

In the Bailian console, go to the Service Channels page and copy the DashScope API Endpoint and API Key.
2

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
3

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:
  1. Select Add MCP Tool
  2. Enter the MCP Server URL and authentication details (obtained from the Service Channels page in the console)
  3. Select the retrieval / Q&A capabilities to expose
Method 2: API Plugin
  1. Create a custom plugin in Coze
  2. Configure an HTTP request pointing to the DashScope retrieval endpoint
  3. Map input parameters (query, top_k) and output parameters (list of chunks)

n8n

n8n can call the RAG retrieval API using the HTTP Request node:
  1. Add an HTTP Request node
  2. Set method to POST and enter the retrieval endpoint URL (see details below)
  3. In Headers, add Authorization: Bearer <API-Key>
  4. 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: query and agent_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]
The above code is for illustration only. When using in production, add proper error handling and retry logic.
All third-party integrations rely on the DashScope API. For full API documentation, see the API Reference.