跳到内容

本地搜索 🔎

基于实体的推理

本地搜索方法将知识图谱中的结构化数据与输入文档中的非结构化数据相结合,在查询时用相关的实体信息增强大型语言模型 (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 调用的附加参数(例如,温度、最大 token 数)的字典
  • context_builder_params: 在为搜索提示构建上下文时,要传递给 context_builder 对象的附加参数的字典
  • callbacks: 可选的回调函数,可用于为LLM的完成流事件提供自定义事件处理程序

如何使用

可在以下笔记本中找到本地搜索场景的示例。