Quick Start
Create a knowledge base in 3 steps and perform one retrieval and Q&A
ImportantWhen you first log in to the console, the RAG Knowledge Base service is automatically activated, and you receive a free quota of 720 hours.
Prerequisites
- Alibaba Cloud account
- API Key (created on the Console API Key page, starting with
sk-) - A PDF / Word / Markdown file and a question whose answer can be found in that file.
Procedure
Create a Document Search knowledge base and wait for its index.
Get an answer with citations in the Playground.
Fetch relevant chunks for your application.
1. Create a knowledge base and upload documents
Go to the console's Knowledge Management and click Create Knowledge Base.
- Enter a name and description. Select Document Search as the knowledge base type and Basic Document Q&A as the use case, then click Next.
- Choose Upload Files as the data source, and drag & drop or click to upload a PDF / Word / Markdown file.
- Keep the indexing settings at their defaults and click Create Knowledge Base.
The system automatically performs parsing, chunking, vectorization, and index building. Once the knowledge base status changes to Ready, it becomes available for retrieval.
ImportantFor complete configuration details—including knowledge base type, use case, chunking strategy, etc.—see Creating a Knowledge Base.
2. Try Q&A in the Playground
Click Playground on the left sidebar, select the knowledge base you just created, switch to Knowledge Q&A at the top, and enter your prepared question.
The system first retrieves relevant chunks, then invokes a large language model to generate an answer with citations. You can switch between different models (e.g., Qwen / DeepSeek) to compare results. Check the answer and citations against the source document.
3. Integrate via API into your application
Follow API service address to obtain the actual workspace_id from Workspace Management in the console. Replace {workspace_id} in the URL below. The API key and knowledge base must belong to this workspace, and the knowledge base must be Ready.
Configure your API key as an environment variable after replacing the placeholder:
export DASHSCOPE_API_KEY="sk-xxxxxxxxxxxxxxxx"
You can copy the index_id by clicking the corresponding knowledge base on the Knowledge Management page. Replace <knowledge-base-id> with that ID and <your-query> with your prepared question, then make a retrieval request:
curl -X POST https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/indices/rag/index/retrieve \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"index_id": "<knowledge-base-id>",
"query": "<your-query>",
"top_k": 5
}'
NoteThe returned nodes array contains matched chunks, sorted in descending order by relevance score. Check the chunks against your question and source document. API retrieval returns relevant content, not a model-generated answer; view the answer with citations in the console Q&A in step 2.
ImportantYou can also retrieve via the Bailian CLI: bl knowledge retrieve --index-id <knowledge-base-id> --query "your query" --top-k 5. See Use the CLI.
Next Steps
Build a Q&A service for streaming responses: Knowledge Q&A. Understand how RAG works: Core Concepts.