Skip to main content

Knowledge Base Logging and Monitoring

Enable knowledge base retrieval logs and use Log Service (SLS) for call auditing, troubleshooting, usage analysis, and alerting.

After retrieval logging is enabled, use Log Service (SLS) to audit, troubleshoot, analyze usage, and configure alerts for knowledge base retrieval calls integrated with logging.
This page uses the underlying knowledge base retrieval endpoint /api/v1/indices/rag/index/retrieve and its data.nodes[] response as the example. Check the path field in actual logs to determine endpoint coverage. Do not treat these logs as complete service traces for /knowledge/search or /knowledge/chat.

Enable and view logs

Log Service (SLS) handles the storage and querying of all retrieval logs. When this feature is enabled, a dedicated Project and LogStore are automatically created in your account. SLS bills the actual storage and traffic separately. For more information, see Log Service billing overview.

First-time use

On the Knowledge Base List page, click Monitoring Configuration in the upper-right corner. The monitoring configuration panel appears. On your first use, the panel guides you through the following tasks:
  1. Authorize Log Service role permissions Role: AliyunServiceRoleForSFMAccessSLS Policy: AliyunServiceRolePolicyForSFMAccessSLS
  2. Enable Log Service Use your Log Service LogStore to collect and store knowledge base logs. This enables real-time viewing and custom log analysis.
  3. Create a Log Service LogStore Refresh the page and click Create LogStore. The Retrieval Logs switch is enabled by default. You can click View Details to access the log repository.
    After the Retrieval Logs switch shows Enabled, knowledge base retrieval calls integrated with logging are delivered to the specified LogStore. The delivery latency is typically within seconds.

View and analyze logs

On the Knowledge Base List page, click Monitoring Configuration in the upper-right corner. In the Store to Log Service section of the panel, click View Details to open the corresponding LogStore in your own account. There, you can use SLS query analysis, dashboards, and alerts. You can also access Log Service through the SLS console.
Turning off the Retrieval Logs switch only stops the delivery of new logs. Previously delivered logs are retained and billed according to your default SLS configuration. To stop billing completely, you must delete the corresponding LogStore in the SLS console.

Field reference

Each retrieval log has the topic log_dispatch and includes the following indexed fields:
FieldTypeDescription
request_idstringA unique ID for a single request. Use this ID to trace a specific call.
pipeline_idstringThe knowledge base ID. Use this field to aggregate statistics by knowledge base.
workspace_idstringThe workspace ID, in the format llm-xxxx. Use this field for usage analysis and isolation across different workspaces.
user_idstringThe UID of the caller.
pathstringThe API path that was called, for example, /api/v1/indices/rag/index/retrieve. Use this field to identify the call source.
latencylongThe request processing time in milliseconds (ms). Use this field for performance monitoring and slow query analysis.
response_status_codelongThe HTTP status code, such as 200, 4xx, or 5xx. Use this field for error monitoring.
response_codestringThe business response code. A successful call returns Success. A failed call returns a dot-separated error code, such as Index.IndexNotExist for a non-existent knowledge base. Use this field with response_status_code and response_message to identify the specific cause of an error.
response_messagestringThe business response message. A successful call returns success. A failed call includes diagnostic information, such as index not exist, index_id: xxx, workspace: llm-xxx.
request_bodyjsonThe request body in JSON format. Use this field for detailed investigation of request parameters.
response_bodyjsonThe response body in JSON format. The top-level structure is {code, status_code, data}. Retrieved chunks are in data.nodes[]. Each node contains score (overall score), text (chunk text), and metadata (including doc_name and doc_id). You can use this field for auditing retrieval results.

Common use cases

The following are common use cases. For more information about the query syntax, see SLS query syntax and SLS analysis syntax.
If you encounter syntax errors, use the Use Copilot feature in the query analysis window to get AI-powered assistance in correcting and generating queries.

Scenario 1: Get usage statistics by knowledge base or workspace

* | select pipeline_id, count(*) as cnt
    group by pipeline_id
    order by cnt desc
Replace pipeline_id with workspace_id to aggregate the results by workspace. Alternatively, remove the aggregation field and use select distinct pipeline_id to obtain a list of active knowledge base IDs.

Scenario 2: Aggregate call volume by API path

* | select path, count(*) as cnt
    group by path
    order by cnt desc
Use this query to see the call distribution across different retrieval interfaces.

Perform more complex analysis

For more complex analysis, such as viewing details of failed requests, calculating statistics over a rolling time window, or performing cross-field queries, use the built-in Use Copilot feature in the SLS query analysis window. Use natural language and the field reference in this document to generate SQL, then run and validate the queries in SLS.

Recommendations

We recommend setting up the following dashboard components and alert categories in Log Service (SLS). Set the specific thresholds based on your business's historical baseline.
Dashboard componentPurpose
Call volume trend (hourly/daily)Monitor overall usage.
Top N knowledge bases by call volumeIdentify core and long-tail knowledge bases.
Alert metricDescription
Business error rate (response_code != 'Success')Monitors business-layer exceptions.
HTTP 5xx error rateMonitors server-side exceptions.