本地搜索 🔎
基于实体的推理
本地搜索方法将知识图谱中的结构化数据与输入文档中的非结构化数据结合起来,在查询时使用相关实体信息来增强 LLM 上下文。它非常适合回答需要理解输入文档中提到的特定实体的问题(例如,“洋甘菊的治疗特性是什么?”)。
方法论
---
title: Local Search Dataflow
---
%%{ init: { 'flowchart': { 'curve': 'step' } } }%%
flowchart LR
uq[User Query] ---.1
ch1[Conversation<br/>History]---.1
.1--Entity<br/>Description<br/>Embedding--> ee[Extracted Entities]
ee[Extracted Entities] ---.2--Entity-Text<br/>Unit Mapping--> ctu[Candidate<br/>Text Units]--Ranking + <br/>Filtering -->ptu[Prioritized<br/>Text Units]---.3
.2--Entity-Report<br/>Mapping--> ccr[Candidate<br/>Community Reports]--Ranking + <br/>Filtering -->pcr[Prioritized<br/>Community Reports]---.3
.2--Entity-Entity<br/>Relationships--> ce[Candidate<br/>Entities]--Ranking + <br/>Filtering -->pe[Prioritized<br/>Entities]---.3
.2--Entity-Entity<br/>Relationships--> cr[Candidate<br/>Relationships]--Ranking + <br/>Filtering -->pr[Prioritized<br/>Relationships]---.3
.2--Entity-Covariate<br/>Mappings--> cc[Candidate<br/>Covariates]--Ranking + <br/>Filtering -->pc[Prioritized<br/>Covariates]---.3
ch1 -->ch2[Conversation History]---.3
.3-->res[Response]
classDef green fill:#26B653,stroke:#333,stroke-width:2px,color:#fff;
classDef turquoise fill:#19CCD3,stroke:#333,stroke-width:2px,color:#fff;
classDef rose fill:#DD8694,stroke:#333,stroke-width:2px,color:#fff;
classDef orange fill:#F19914,stroke:#333,stroke-width:2px,color:#fff;
classDef purple fill:#B356CD,stroke:#333,stroke-width:2px,color:#fff;
classDef invisible fill:#fff,stroke:#fff,stroke-width:0px,color:#fff, width:0px;
class uq,ch1 turquoise
class ee green
class ctu,ccr,ce,cr,cc rose
class ptu,pcr,pe,pr,pc,ch2 orange
class res purple
class .1,.2,.3 invisible
给定用户查询,以及可选的对话历史记录,本地搜索方法从知识图谱中识别出一组与用户输入语义相关的实体。 这些实体作为访问知识图谱的入口点,可以提取更多相关详细信息,例如连接的实体、关系、实体协变量和社区报告。 此外,它还会从与已识别实体相关的原始输入文档中提取相关的文本块。 然后对这些候选数据源进行优先级排序和过滤,以适应预定义大小的单个上下文窗口,该窗口用于生成对用户查询的响应。
配置
以下是 LocalSearch 类的关键参数
llm
:用于生成响应的 OpenAI 模型对象context_builder
:用于准备来自知识模型对象集合的上下文数据的上下文构建器对象system_prompt
:用于生成搜索响应的提示模板。默认模板可以在system_prompt中找到response_type
:描述所需响应类型和格式的自由形式文本(例如,多个段落
,多页报告
)llm_params
:要传递给 LLM 调用的其他参数的字典(例如,温度、max_tokens)context_builder_params
:构建搜索提示的上下文时,要传递给context_builder
对象的其他参数的字典callbacks
:可选的回调函数,可用于为 LLM 的完成流事件提供自定义事件处理程序
如何使用
可以在以下notebook中找到本地搜索方案的示例。