用户开发指南
更新时间:2026-05-13
可用依赖服务
- 本体查询服务
- embedding 模型服务
- rerank 模型服务
接口详情:https://docs.apipost.net/docs/56bf085e88ca000?locale=zh-cn
依赖服务的 endpoint 通过环境变量引用。
开发约束
Plain Text
1# 运行环境: Python3;预置 Package:NumPy
2# 定义函数: 定义一个 main 函数,传入 params 参数
3# 输入变量: params 类型为字典,包含了 block 配置的输入变量
4# 输出变量: 定义一个字典作为输出变量
5
6# 通过环境变量引用依赖服务的 endpoint, 用户在 block 配置服务后,自动更新环境变量
7# 本地查询: OBJECT_QUERY_ENDPOINT_FOR_SEARCH
8# embedding: EMBEDDING_ENDPOINT_FOR_SEARCH
9# rerank: RERANK_ENDPOINT_FOR_SEARCH
10# 通过环境变量引用 api_key
11# api_key: API_KEY_FOR_SEARCH
12
13def main(params):
14 ##################################################
15 ################### 输入 ##########################
16 # params 类型为字典,字典中元素的值分为简单类型和复杂类型
17 # ——————————— params —————————————————————————————————— 引用变量 ———————————
18 # {
19 # "query": "天气", # params["query"]
20 # "ontology": { # params["ontology"]
21 # "ontology_name": "city", # params["ontology"]["ontology_name"]
22 # "fulltext_column": "txt", # params["ontology"]["fulltext_column"]
23 # "fulltext_column": "embed", # params["ontology"]["semantic_column"]
24 # },
25 # "metadata_filters": { # params["metadata_filters"]
26 # "condition": "or", # params["metadata_filters"]["condition"]
27 # "filters": [ # params["metadata_filters"]["filters"]
28 # {
29 # "operator": "in",
30 # "field": "doc_id",
31 # "value": [
32 # "b92f3308af",
33 # "c3822cf20a"
34 # ]
35 # }
36 # ]
37 # },
38 #
39 # }
40
41
42
43
44 ###########################################
45 ################### 输出 ###################
46 # 创建一个字典作为输出变量
47 output_object ={
48 # 必须项,0 表示执行成功,-1 表示执行失败
49 "code": 0,
50
51 # code 为 0 时,message 为可选项
52 # code 为 -1 时,message 为必须项,包含具体错误信息
53 "message": "",
54
55 # code 为 0 时, chunk 为必须项
56 # chunk 的 value 类型为 list, list 的元素为字典且 chunk_id、content、object_type 和 ontology 为必须项
57 "chunk": [
58 {
59 "chunk_id": "1f073ffe-3186-4df1-8020-934501892c5a",
60 "content": "沧海一声笑",
61 "object_type": "person",
62 "ontology": "xxxx",
63 },
64 {
65 "chunk_id": "1f073ffe-3186-4df1-8020-934501892c5b",
66 "content": "床前明月光",
67 "object_type": "person"
68 "ontology": "xxxx"
69 }
70 ]
71 }
72
73 # 返回输出字典类型变量 output_object,包含所需的输出数据
74 return output_object
评价此篇文章
