数据源

AnalyzeDataStream / analyze_data_stream 通过请求中的 config.data_source 限制本次分析可访问的表和文件。数据范围是每次请求的配置,不会创建持久化知识库。

数据源结构

Go SDK 的公开类型是 DataSource

字段

作用

Type / type

allspecified

使用全部可用来源,或按 tables / files 指定

Tables / tables

DataAskingTableConfig

表范围

Files / files

FileConfig

文件范围

表配置:

JSON 字段

可用值或含义

type

allnonespecified

db_name

数据库名称;必填

database_id

选择数据库全部表时使用的数值 ID

table_list

specified 时使用的表名数组

文件配置:

JSON 字段

可用值或含义

type

allnonespecified

database_id

选择数据库全部文件时使用的数值 ID

file_id_list

specified 时使用的文件 ID 数组

all 的实际范围仍受当前身份权限和服务端策略限制。生产应用更适合使用 specified,明确记录每次请求允许访问的来源。

仅查询指定表

Python:

request = {
    "question": "Show the monthly order totals.",
    "config": {
        "data_source": {
            "type": "specified",
            "tables": {
                "type": "specified",
                "db_name": "sales",
                "table_list": ["orders"],
            },
            "files": {"type": "none"},
        }
    },
}

stream = raw.analyze_data_stream(request)

Go:

req := &sdk.DataAnalysisRequest{
    Question: "Show the monthly order totals.",
    Config: &sdk.DataAnalysisConfig{
        DataSource: &sdk.DataSource{
            Type: "specified",
            Tables: &sdk.DataAskingTableConfig{
                Type:      "specified",
                DbName:    "sales",
                TableList: []string{"orders"},
            },
            Files: &sdk.FileConfig{Type: "none"},
        },
    },
}

stream, err := client.AnalyzeDataStream(ctx, req)

仅检索指定文件

Python:

request = {
    "question": "Summarize the renewal conditions.",
    "config": {
        "data_source": {
            "type": "specified",
            "files": {
                "type": "specified",
                "file_id_list": selected_file_ids,
            },
        }
    },
}

文件 ID 应通过 Catalog 文件 API 取得。不要传文件名、路径或知识项 ID。

组合表与文件

同一个 DataSource 可以同时指定表和文件。服务会通过流事件的 source 区分 RAG 与 NL2SQL 过程。组合查询前分别验证两边:

  1. 用只包含表的请求确认表名、数据库名和 SQL 结果。

  2. 用只包含文件的请求确认文件可以召回。

  3. 再合并范围,并在最终回答中检查两类证据。

这样比直接调试一个混合范围更容易判断是来源选择、权限、检索还是 SQL 的问题。

其他范围字段

DataAnalysisConfig 还公开 data_scopefilter_conditionscontext_config 等字段。这些字段面向组织范围、过滤和知识项数量控制,不等同于 data_source。只在部署方确认含义后使用:

  • DataScope 支持 all / specified,并可携带组织代码组。

  • FilterConditions.Type 的源码注释列出 allnon_inter_data

  • ContextConfig 控制返回给分析过程的知识项数量和单条值长度。

不要用这些字段代替表和文件选择。

提交前校验

  • specified 表范围包含非空 db_name 和真实表名。

  • specified 文件范围只包含 Catalog 文件 ID。

  • 不使用的可选分支保持省略;需要显式传递时使用 none,并遵守该分支的必填字段。

  • 调用身份对每个对象都有读取或查询权限。

  • 记录本次来源配置和初始化事件中的 request_id,便于复现。

接下来参阅 流式查询消费返回流。