局部搜索
In [1]
已复制!
# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License.
# 版权所有 (c) 2024 Microsoft Corporation。 # 根据 MIT 许可证获得许可。
In [2]
已复制!
import os
import pandas as pd
from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig
from graphrag.query.context_builder.entity_extraction import EntityVectorStoreKey
from graphrag.query.indexer_adapters import (
read_indexer_covariates,
read_indexer_entities,
read_indexer_relationships,
read_indexer_reports,
read_indexer_text_units,
)
from graphrag.query.question_gen.local_gen import LocalQuestionGen
from graphrag.query.structured_search.local_search.mixed_context import (
LocalSearchMixedContext,
)
from graphrag.query.structured_search.local_search.search import LocalSearch
from graphrag.vector_stores.lancedb import LanceDBVectorStore
import os import pandas as pd from graphrag.config.models.vector_store_schema_config import VectorStoreSchemaConfig from graphrag.query.context_builder.entity_extraction import EntityVectorStoreKey from graphrag.query.indexer_adapters import ( read_indexer_covariates, read_indexer_entities, read_indexer_relationships, read_indexer_reports, read_indexer_text_units, ) from graphrag.query.question_gen.local_gen import LocalQuestionGen from graphrag.query.structured_search.local_search.mixed_context import ( LocalSearchMixedContext, ) from graphrag.query.structured_search.local_search.search import LocalSearch from graphrag.vector_stores.lancedb import LanceDBVectorStore
本地搜索示例¶
本地搜索方法通过将AI提取的知识图中的相关数据与原始文档的文本块相结合来生成答案。此方法适用于需要理解文档中提到的特定实体的问题(例如,洋甘菊的药用特性是什么?)。
加载文本单元和图数据表作为本地搜索的上下文¶
- 在此测试中,我们首先将parquet文件中的索引输出加载到数据帧中,然后将这些数据帧转换为与知识模型对齐的数据对象集合。
将表加载到数据帧¶
In [3]
已复制!
INPUT_DIR = "./inputs/operation dulce"
LANCEDB_URI = f"{INPUT_DIR}/lancedb"
COMMUNITY_REPORT_TABLE = "community_reports"
ENTITY_TABLE = "entities"
COMMUNITY_TABLE = "communities"
RELATIONSHIP_TABLE = "relationships"
COVARIATE_TABLE = "covariates"
TEXT_UNIT_TABLE = "text_units"
COMMUNITY_LEVEL = 2
INPUT_DIR = "./inputs/operation dulce" LANCEDB_URI = f"{INPUT_DIR}/lancedb" COMMUNITY_REPORT_TABLE = "community_reports" ENTITY_TABLE = "entities" COMMUNITY_TABLE = "communities" RELATIONSHIP_TABLE = "relationships" COVARIATE_TABLE = "covariates" TEXT_UNIT_TABLE = "text_units" COMMUNITY_LEVEL = 2
读取实体¶
In [4]
已复制!
# read nodes table to get community and degree data
entity_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_TABLE}.parquet")
community_df = pd.read_parquet(f"{INPUT_DIR}/{COMMUNITY_TABLE}.parquet")
entities = read_indexer_entities(entity_df, community_df, COMMUNITY_LEVEL)
# load description embeddings to an in-memory lancedb vectorstore
# to connect to a remote db, specify url and port values.
description_embedding_store = LanceDBVectorStore(
vector_store_schema_config=VectorStoreSchemaConfig(
index_name="default-entity-description"
)
)
description_embedding_store.connect(db_uri=LANCEDB_URI)
print(f"Entity count: {len(entity_df)}")
entity_df.head()
# 读取节点表以获取社区和度数数据 entity_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_TABLE}.parquet") community_df = pd.read_parquet(f"{INPUT_DIR}/{COMMUNITY_TABLE}.parquet") entities = read_indexer_entities(entity_df, community_df, COMMUNITY_LEVEL) # 将描述嵌入加载到内存中的lancedb向量存储中 # 要连接到远程数据库,请指定url和port值。 description_embedding_store = LanceDBVectorStore( vector_store_schema_config=VectorStoreSchemaConfig( index_name="default-entity-description" ) ) description_embedding_store.connect(db_uri=LANCEDB_URI) print(f"实体计数: {len(entity_df)}") entity_df.head()
Entity count: 18
输出[4]
| id | human_readable_id | title | 类型 | 描述 | text_unit_ids | 频率 | 度数 | x | y | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 425a7862-0aef-4f69-a4c8-8bd42151c9d4 | 0 | ALEX MERCER | PERSON | 特工亚历克斯·默瑟是一位坚定的个体,他... | [8e938693af886bfd081acbbe8384c3671446bff84a134... | 4 | 9 | 0 | 0 |
| 1 | bcdbf1fc-0dc1-460f-bc71-2781729c96ba | 1 | TAYLOR CRUZ | PERSON | 特工泰勒·克鲁兹是一位指挥有力、权威... | [8e938693af886bfd081acbbe8384c3671446bff84a134... | 4 | 8 | 0 | 0 |
| 2 | ef02ef24-5762-46ce-93ce-7dea6fc86595 | 2 | JORDAN HAYES | PERSON | 乔丹·海耶斯博士是一位科学家,也是... | [8e938693af886bfd081acbbe8384c3671446bff84a134... | 4 | 9 | 0 | 0 |
| 3 | 8b163d27-e43a-4a2c-a26f-866778d8720e | 3 | SAM RIVERA | PERSON | 萨姆·里维拉是一位网络安全专家和才华横溢的... | [8e938693af886bfd081acbbe8384c3671446bff84a134... | 4 | 8 | 0 | 0 |
| 4 | 542aa5bd-ba2d-400a-8488-c52d50bc300d | 4 | PARANORMAL MILITARY SQUAD | ORGANIZATION | 超自然军事小队是一个精英团体,... | [8e938693af886bfd081acbbe8384c3671446bff84a134... | 2 | 6 | 0 | 0 |
读取关系¶
In [5]
已复制!
relationship_df = pd.read_parquet(f"{INPUT_DIR}/{RELATIONSHIP_TABLE}.parquet")
relationships = read_indexer_relationships(relationship_df)
print(f"Relationship count: {len(relationship_df)}")
relationship_df.head()
relationship_df = pd.read_parquet(f"{INPUT_DIR}/{RELATIONSHIP_TABLE}.parquet") relationships = read_indexer_relationships(relationship_df) print(f"关系计数: {len(relationship_df)}") relationship_df.head()
Relationship count: 54
输出[5]
| id | human_readable_id | 源 | 目标 | 描述 | 权重 | 组合度 | text_unit_ids | |
|---|---|---|---|---|---|---|---|---|
| 0 | 2bfad9f4-5abd-48d0-8db3-a9cad9120413 | 0 | ALEX MERCER | TAYLOR CRUZ | 亚历克斯·默瑟和泰勒·克鲁兹都是在... | 37.0 | 17 | [8e938693af886bfd081acbbe8384c3671446bff84a134... |
| 1 | 6cbb838f-9e83-4086-a684-15c8ed709e52 | 1 | ALEX MERCER | JORDAN HAYES | 亚历克斯·默瑟和乔丹·海耶斯都是在... | 42.0 | 18 | [8e938693af886bfd081acbbe8384c3671446bff84a134... |
| 2 | bfdc25f1-80ca-477b-a304-94465b69e680 | 2 | ALEX MERCER | SAM RIVERA | 亚历克斯·默瑟和萨姆·里维拉都是特工,并且... | 26.0 | 17 | [8e938693af886bfd081acbbe8384c3671446bff84a134... |
| 3 | 7a7e943d-a4f5-487b-9625-5d0907c4c26d | 3 | ALEX MERCER | PARANORMAL MILITARY SQUAD | 亚历克斯·默瑟是超自然军事小队的成员... | 17.0 | 15 | [8e938693af886bfd081acbbe8384c3671446bff84a134... |
| 4 | 5e00bcb9-a17e-4c27-8241-6ebb286a7fc6 | 4 | ALEX MERCER | DULCE | 亚历克斯·默瑟正准备带领团队进入... | 15.0 | 14 | [8e938693af886bfd081acbbe8384c3671446bff84a134... |
In [6]
已复制!
# NOTE: covariates are turned off by default, because they generally need prompt tuning to be valuable
# Please see the GRAPHRAG_CLAIM_* settings
covariate_df = pd.read_parquet(f"{INPUT_DIR}/{COVARIATE_TABLE}.parquet")
claims = read_indexer_covariates(covariate_df)
print(f"Claim records: {len(claims)}")
covariates = {"claims": claims}
# 注意:默认情况下,协变量是关闭的,因为它们通常需要进行提示调优才能有价值 # 请参阅GRAPHRAG_CLAIM_*设置 covariate_df = pd.read_parquet(f"{INPUT_DIR}/{COVARIATE_TABLE}.parquet") claims = read_indexer_covariates(covariate_df) print(f"声明记录: {len(claims)}") covariates = {"claims": claims}
Claim records: 17
读取社区报告¶
In [7]
已复制!
report_df = pd.read_parquet(f"{INPUT_DIR}/{COMMUNITY_REPORT_TABLE}.parquet")
reports = read_indexer_reports(report_df, community_df, COMMUNITY_LEVEL)
print(f"Report records: {len(report_df)}")
report_df.head()
report_df = pd.read_parquet(f"{INPUT_DIR}/{COMMUNITY_REPORT_TABLE}.parquet") reports = read_indexer_reports(report_df, community_df, COMMUNITY_LEVEL) print(f"报告记录: {len(report_df)}") report_df.head()
Report records: 2
输出[7]
| id | human_readable_id | community | level | parent | children | title | summary | full_content | rank | rating_explanation | findings | full_content_json | period | size | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6c3a555680d647ac8be866a129c7b0ea | 0 | 0 | 0 | -1 | [] | 行动:杜尔塞和杜尔塞基地探索 | 社区围绕着“行动:杜尔塞”展开... | # 行动:杜尔塞和杜尔塞基地探索\... | 8.5 | 由于影响,影响严重性评级很高... | [{'explanation': '行动:杜尔塞是一项重要... | {\n "title": "行动:杜尔塞和杜尔塞基... | 2025-03-04 | 7 |
| 1 | 0127331a1ea34b8ba19de2c2a4cb3bc9 | 1 | 1 | 0 | -1 | [] | 超自然军事小队和行动:杜尔塞 | 社区围绕着超自然军事小队展开... | # 超自然军事小队和行动:杜尔塞... | 8.5 | 由于影响,影响严重性评级很高... | [{'explanation': '特工亚历克斯·默瑟是一个关键的... | {\n "title": "超自然军事小队和..." | 2025-03-04 | 9 |
读取文本单元¶
In [8]
已复制!
text_unit_df = pd.read_parquet(f"{INPUT_DIR}/{TEXT_UNIT_TABLE}.parquet")
text_units = read_indexer_text_units(text_unit_df)
print(f"Text unit records: {len(text_unit_df)}")
text_unit_df.head()
text_unit_df = pd.read_parquet(f"{INPUT_DIR}/{TEXT_UNIT_TABLE}.parquet") text_units = read_indexer_text_units(text_unit_df) print(f"文本单元记录: {len(text_unit_df)}") text_unit_df.head()
Text unit records: 5
输出[8]
| id | human_readable_id | text | n_tokens | 文档 ID | 实体 ID | 关系 ID | 协变量 ID | |
|---|---|---|---|---|---|---|---|---|
| 0 | 8e938693af886bfd081acbbe8384c3671446bff84a134a... | 1 | # 行动:杜尔塞\n\n## 第一章\n\n通过... | 1200 | [6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a8... | [425a7862-0aef-4f69-a4c8-8bd42151c9d4, bcdbf1f... | [2bfad9f4-5abd-48d0-8db3-a9cad9120413, 6cbb838... | [745d28dd-be20-411b-85ff-1c69ca70e7b3, 9cba185... |
| 1 | fd1f46d32e1df6cd429542aeda3d64ddf3745ccb80f443... | 2 | ,海湾的空洞回声清晰地提醒着... | 1200 | [6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a8... | [425a7862-0aef-4f69-a4c8-8bd42151c9d4, bcdbf1f... | [2bfad9f4-5abd-48d0-8db3-a9cad9120413, 6cbb838... | [4f9b461f-5e8f-465d-9586-e2fc81787062, 0f74618... |
| 2 | 7296d9a1f046854d59079dc183de8a054c27c4843d2979... | 3 | 与他人的赞扬不同。这是... | 1200 | [6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a8... | [425a7862-0aef-4f69-a4c8-8bd42151c9d4, bcdbf1f... | [2bfad9f4-5abd-48d0-8db3-a9cad9120413, 6cbb838... | [3ef1be9c-4080-4fac-99bd-c4a636248904, 8730b20... |
| 3 | ac72722a02ac71242a2a91fca323198d04197daf60515d... | 4 | 与笼罩着... | 1200 | [6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a8... | [425a7862-0aef-4f69-a4c8-8bd42151c9d4, bcdbf1f... | [2bfad9f4-5abd-48d0-8db3-a9cad9120413, 6cbb838... | [2c292047-b79a-4958-ab57-7bf7d7a22c92, 3cbd18a... |
| 4 | 4c277337d461a16aaf8f9760ddb8b44ef220e948a2341d... | 5 | 职责的面具。\n\n在下降的过程中... | 35 | [6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a8... | [d084d615-3584-4ec8-9931-90aa6075c764, 4b84859... | [6efdc42e-69a2-47c0-97ec-4b296cd16d5e] | [db8da02f-f889-4bb5-8e81-ab2a72e380bb] |
In [9]
已复制!
from graphrag.config.enums import ModelType
from graphrag.config.models.language_model_config import LanguageModelConfig
from graphrag.language_model.manager import ModelManager
from graphrag.tokenizer.get_tokenizer import get_tokenizer
api_key = os.environ["GRAPHRAG_API_KEY"]
chat_config = LanguageModelConfig(
api_key=api_key,
type=ModelType.Chat,
model_provider="openai",
model="gpt-4.1",
max_retries=20,
)
chat_model = ModelManager().get_or_create_chat_model(
name="local_search",
model_type=ModelType.Chat,
config=chat_config,
)
embedding_config = LanguageModelConfig(
api_key=api_key,
type=ModelType.Embedding,
model_provider="openai",
model="text-embedding-3-small",
max_retries=20,
)
text_embedder = ModelManager().get_or_create_embedding_model(
name="local_search_embedding",
model_type=ModelType.Embedding,
config=embedding_config,
)
tokenizer = get_tokenizer(chat_config)
from graphrag.config.enums import ModelType from graphrag.config.models.language_model_config import LanguageModelConfig from graphrag.language_model.manager import ModelManager from graphrag.tokenizer.get_tokenizer import get_tokenizer api_key = os.environ["GRAPHRAG_API_KEY"] chat_config = LanguageModelConfig( api_key=api_key, type=ModelType.Chat, model_provider="openai", model="gpt-4.1", max_retries=20, ) chat_model = ModelManager().get_or_create_chat_model( name="local_search", model_type=ModelType.Chat, config=chat_config, ) embedding_config = LanguageModelConfig( api_key=api_key, type=ModelType.Embedding, model_provider="openai", model="text-embedding-3-small", max_retries=20, ) text_embedder = ModelManager().get_or_create_embedding_model( name="local_search_embedding", model_type=ModelType.Embedding, config=embedding_config, ) tokenizer = get_tokenizer(chat_config)
创建本地搜索上下文构建器¶
In [10]
已复制!
context_builder = LocalSearchMixedContext(
community_reports=reports,
text_units=text_units,
entities=entities,
relationships=relationships,
# if you did not run covariates during indexing, set this to None
covariates=covariates,
entity_text_embeddings=description_embedding_store,
embedding_vectorstore_key=EntityVectorStoreKey.ID, # if the vectorstore uses entity title as ids, set this to EntityVectorStoreKey.TITLE
text_embedder=text_embedder,
tokenizer=tokenizer,
)
context_builder = LocalSearchMixedContext( community_reports=reports, text_units=text_units, entities=entities, relationships=relationships, # 如果您在索引期间未运行协变量,请将其设置为None covariates=covariates, entity_text_embeddings=description_embedding_store, embedding_vectorstore_key=EntityVectorStoreKey.ID, # 如果向量存储使用实体标题作为ID,请将其设置为EntityVectorStoreKey.TITLE text_embedder=text_embedder, tokenizer=tokenizer, )
创建本地搜索引擎¶
In [11]
已复制!
# text_unit_prop: proportion of context window dedicated to related text units
# community_prop: proportion of context window dedicated to community reports.
# The remaining proportion is dedicated to entities and relationships. Sum of text_unit_prop and community_prop should be <= 1
# conversation_history_max_turns: maximum number of turns to include in the conversation history.
# conversation_history_user_turns_only: if True, only include user queries in the conversation history.
# top_k_mapped_entities: number of related entities to retrieve from the entity description embedding store.
# top_k_relationships: control the number of out-of-network relationships to pull into the context window.
# include_entity_rank: if True, include the entity rank in the entity table in the context window. Default entity rank = node degree.
# include_relationship_weight: if True, include the relationship weight in the context window.
# include_community_rank: if True, include the community rank in the context window.
# return_candidate_context: if True, return a set of dataframes containing all candidate entity/relationship/covariate records that
# could be relevant. Note that not all of these records will be included in the context window. The "in_context" column in these
# dataframes indicates whether the record is included in the context window.
# max_tokens: maximum number of tokens to use for the context window.
local_context_params = {
"text_unit_prop": 0.5,
"community_prop": 0.1,
"conversation_history_max_turns": 5,
"conversation_history_user_turns_only": True,
"top_k_mapped_entities": 10,
"top_k_relationships": 10,
"include_entity_rank": True,
"include_relationship_weight": True,
"include_community_rank": False,
"return_candidate_context": False,
"embedding_vectorstore_key": EntityVectorStoreKey.ID, # set this to EntityVectorStoreKey.TITLE if the vectorstore uses entity title as ids
"max_tokens": 12_000, # change this based on the token limit you have on your model (if you are using a model with 8k limit, a good setting could be 5000)
}
model_params = {
"max_tokens": 2_000, # change this based on the token limit you have on your model (if you are using a model with 8k limit, a good setting could be 1000=1500)
"temperature": 0.0,
}
# text_unit_prop: 上下文窗口中用于相关文本单元的比例 # community_prop: 上下文窗口中用于社区报告的比例。 # 剩余比例用于实体和关系。text_unit_prop和community_prop的总和应<= 1 # conversation_history_max_turns: 对话历史中包含的最大轮数。 # conversation_history_user_turns_only: 如果为True,则只在对话历史中包含用户查询。 # top_k_mapped_entities: 从实体描述嵌入存储中检索的相关实体数量。 # top_k_relationships: 控制拉入上下文窗口的非网络关系的数量。 # include_entity_rank: 如果为True,则在上下文窗口的实体表中包含实体排名。默认实体排名=节点度数。 # include_relationship_weight: 如果为True,则在上下文窗口中包含关系权重。 # include_community_rank: 如果为True,则在上下文窗口中包含社区排名。 # return_candidate_context: 如果为True,则返回一组数据帧,其中包含所有可能相关的候选实体/关系/协变量记录。 # 请注意,并非所有这些记录都将包含在上下文窗口中。这些数据帧中的“in_context”列表示记录是否包含在上下文窗口中。 # max_tokens: 上下文窗口使用的最大令牌数。 local_context_params = { "text_unit_prop": 0.5, "community_prop": 0.1, "conversation_history_max_turns": 5, "conversation_history_user_turns_only": True, "top_k_mapped_entities": 10, "top_k_relationships": 10, "include_entity_rank": True, "include_relationship_weight": True, "include_community_rank": False, "return_candidate_context": False, "embedding_vectorstore_key": EntityVectorStoreKey.ID, # 如果向量存储使用实体标题作为ID,请将其设置为EntityVectorStoreKey.TITLE "max_tokens": 12_000, # 根据您的模型令牌限制更改此值(如果您使用8k限制的模型,则一个好的设置可能是5000) } model_params = { "max_tokens": 2_000, # 根据您的模型令牌限制更改此值(如果您使用8k限制的模型,则一个好的设置可能是1000=1500) "temperature": 0.0, }
输入[12]
已复制!
search_engine = LocalSearch(
model=chat_model,
context_builder=context_builder,
tokenizer=tokenizer,
model_params=model_params,
context_builder_params=local_context_params,
response_type="multiple paragraphs", # free form text describing the response type and format, can be anything, e.g. prioritized list, single paragraph, multiple paragraphs, multiple-page report
)
search_engine = LocalSearch( model=chat_model, context_builder=context_builder, tokenizer=tokenizer, model_params=model_params, context_builder_params=local_context_params, response_type="多个段落", # 描述响应类型和格式的自由格式文本,可以是任何内容,例如:优先级列表、单个段落、多个段落、多页报告 )
在示例查询上运行本地搜索¶
输入[13]
已复制!
result = await search_engine.search("Tell me about Agent Mercer")
print(result.response)
result = await search_engine.search("告诉我关于特工默瑟的事") print(result.response)
Warning: No community records added when building community context.
Reached token limit - reverting to previous context state
## Overview of Agent Alex Mercer Agent Alex Mercer is a central figure within the Paranormal Military Squad, playing a crucial role in Operation: Dulce, the mission to explore and uncover the secrets of the mysterious Dulce base. Mercer is characterized by his determination, leadership qualities, and a nuanced internal conflict between strict adherence to protocol and a natural inclination to question and explore beyond the surface. He is respected by his peers for his expertise and is often seen as a guiding force within the team [Data: Entities (0); Relationships (3, 17, 24, 23, 4, +more)]. ## Role in Operation: Dulce Mercer is directly involved in Operation: Dulce, both as a leader and as an active participant in the exploration of the Dulce base. He is responsible for guiding the team, making critical decisions, and ensuring the mission's objectives are met. His leadership is not without its challenges, as he must balance the demands of protocol—often emphasized by Agent Taylor Cruz—with his own investigative instincts. This internal struggle is highlighted in his interactions with Cruz and his reflective moments during mission briefings [Data: Relationships (0, 3, 4, 5, 17, 24, 23, +more); Claims (3, 5)]. ## Relationships and Team Dynamics Mercer maintains strong professional relationships with other key members of the squad. He shares a mutual respect and understanding with Dr. Jordan Hayes, particularly admiring Hayes's analytical abilities and scientific expertise. Their collaboration is marked by a shared commitment to discovery and a willingness to challenge the status quo when necessary [Data: Relationships (1, 10, 25, 41, +more)]. Mercer also acts as a mentor to Sam Rivera, providing guidance and support, and recognizing Rivera's technical skills as vital to the mission's success [Data: Relationships (2, 15, 16, 30, +more)]. His relationship with Taylor Cruz is more complex, defined by a professional rivalry and a competitive undercurrent. While Mercer acknowledges Cruz's authority and often follows their lead, he is not afraid to question decisions or advocate for a more flexible approach when the situation demands it [Data: Relationships (0, 5, 6, 19, +more)]. ## Personality and Motivations Mercer is depicted as someone who feels the weight of responsibility deeply, often reflecting on the broader implications of their mission for humanity. He is not content with simply following orders; instead, he seeks to understand the true significance of their discoveries and the potential impact on the world. This sense of duty, combined with his curiosity and willingness to challenge established norms, makes him a dynamic and sometimes conflicted leader [Data: Claims (3, 5); Sources (0, 3)]. ## Key Contributions - **Leadership:** Mercer is often at the forefront of mission planning and execution, guiding the team through high-stakes situations [Data: Relationships (4, 17, 24, 23, +more)]. - **Mentorship:** He provides mentorship to Sam Rivera, helping to develop Rivera's skills and confidence [Data: Relationships (2, 15)]. - **Collaboration:** Mercer works closely with Dr. Jordan Hayes, leveraging their combined expertise to solve complex problems related to alien technology [Data: Relationships (1, 10, 48, +more)]. - **Adaptability:** Despite his respect for protocol, Mercer is willing to adapt and question orders when necessary, demonstrating flexibility in the face of the unknown [Data: Claims (3); Sources (0, 3)]. ## Conclusion Agent Alex Mercer stands out as a determined, thoughtful, and adaptable leader within the Paranormal Military Squad. His ability to balance protocol with critical thinking, foster strong team relationships, and maintain a sense of duty makes him indispensable to Operation: Dulce and the ongoing efforts to unravel the mysteries of the Dulce base [Data: Entities (0, 4, 5, 7, 8); Relationships (1, 2, 3, 4, 5, 6, 17, 23, 24, +more); Claims (3, 5)].
输入[14]
已复制!
question = "Tell me about Dr. Jordan Hayes"
result = await search_engine.search(question)
print(result.response)
question = "告诉我关于乔丹·海耶斯博士的事" result = await search_engine.search(question) print(result.response)
Warning: No community records added when building community context.
Reached token limit - reverting to previous context state
## Overview of Dr. Jordan Hayes Dr. Jordan Hayes is a scientist and a key member of the Paranormal Military Squad, recognized for their expertise in physics and their composed, analytical demeanor. Hayes is deeply involved in Operation: Dulce, a mission focused on investigating alien technology and its implications for humanity. Their role is characterized by a reflective and skeptical approach, often advocating for adaptability and critical thinking in the face of unknown variables [Data: Entities (2, 4, 5); Relationships (10, 27, 48, 51, +more)]. ## Role in Operation: Dulce Dr. Hayes is directly engaged in working with alien technology, often found in the lab meticulously analyzing enigmatic circuitry retrieved from the Dulce base. Their scientific insights are crucial to the team's understanding of the potential paradigm shifts that such technology could bring. Hayes is not only responsible for providing analytical assessments but also for identifying hidden elements within the base, such as a suspicious panel that suggested concealed secrets [Data: Entities (2, 13, 8); Relationships (48, 51, 26, 11, +more); Claims (10, 6)]. ## Team Dynamics and Relationships Within the Paranormal Military Squad, Hayes is respected for their analytical mind and is seen as a voice of reason, often challenging the strict adherence to protocols favored by Agent Taylor Cruz. This skepticism and emphasis on adaptability create a dynamic tension within the team, particularly during mission briefings and critical decision points. Hayes shares a mutual respect and understanding with Agent Alex Mercer, with both agents valuing each other's expertise and commitment to the mission. Their interactions are marked by a blend of professional camaraderie and a shared drive to uncover the truth behind the Dulce base [Data: Entities (2, 0, 1, 7); Relationships (1, 5, 25, 9, +more); Claims (2, 6)]. ## Notable Characteristics and Contributions Hayes is portrayed as someone who balances scientific rigor with a willingness to question established procedures. They are reflective, often contemplating the broader implications of their discoveries for humanity. Their recent actions have shown newfound assertiveness, particularly as the team prepares to enter and explore the Dulce base. Hayes's ability to identify anomalies and provide critical insights has made them an indispensable asset to the squad [Data: Entities (2); Claims (10, 6, 2)]. ## Summary In summary, Dr. Jordan Hayes stands out as a thoughtful, analytical, and adaptable scientist within the Paranormal Military Squad. Their expertise in physics, commitment to understanding alien technology, and willingness to challenge protocol make them a central figure in Operation: Dulce and a vital contributor to the team's efforts to navigate the mysteries of the Dulce base [Data: Entities (2, 4, 5); Relationships (10, 27, 48, 51, +more); Claims (10, 6, 2)].
检查用于生成响应的上下文数据¶
输入[15]
已复制!
result.context_data["entities"].head()
result.context_data["entities"].head()
输出[15]
| id | 实体 | 描述 | 关系数量 | 在上下文中 | |
|---|---|---|---|---|---|
| 0 | 15 | 简报室 | 2 | True | |
| 1 | 6 | DULCE | 5 | True | |
| 2 | 7 | 团队 | 该团队是一群准备... | 5 | True |
| 3 | 3 | SAM RIVERA | 萨姆·里维拉是一位网络安全专家和才华横溢的... | 8 | True |
| 4 | 2 | JORDAN HAYES | 乔丹·海耶斯博士是一位科学家,也是... | 9 | True |
输入[16]
已复制!
result.context_data["relationships"].head()
result.context_data["relationships"].head()
输出[16]
| id | 源 | 目标 | 描述 | 权重 | 链接 | 在上下文中 | |
|---|---|---|---|---|---|---|---|
| 0 | 24 | ALEX MERCER | 行动:杜尔塞 | 亚历克斯·默瑟参与并是行动的成员... | 24.0 | 7 | True |
| 1 | 27 | JORDAN HAYES | 行动:杜尔塞 | 乔丹·海耶斯是“行动:杜尔塞”的一部分 | 8.0 | 7 | True |
| 2 | 48 | 行动:杜尔塞 | JORDAN HAYES | 乔丹·海耶斯正在研究外星技术,因为... | 16.0 | 7 | True |
| 3 | 1 | ALEX MERCER | JORDAN HAYES | 亚历克斯·默瑟和乔丹·海耶斯都是在... | 42.0 | 6 | True |
| 4 | 31 | SAM RIVERA | 行动:杜尔塞 | 萨姆·里维拉是“行动:杜尔塞”的一部分 | 1.0 | 7 | True |
输入[17]
已复制!
if "reports" in result.context_data:
result.context_data["reports"].head()
if "reports" in result.context_data: result.context_data["reports"].head()
输入[18]
已复制!
result.context_data["sources"].head()
result.context_data["sources"].head()
输出[18]
| id | text | |
|---|---|---|
| 0 | 3 | 与笼罩着... |
| 1 | 0 | # 行动:杜尔塞\n\n## 第一章\n\n通过... |
| 2 | 1 | ,海湾的空洞回声清晰地提醒着... |
输入[19]
已复制!
if "claims" in result.context_data:
print(result.context_data["claims"].head())
if "claims" in result.context_data: print(result.context_data["claims"].head())
id entity object_id status start_date end_date \
0 4 SAM RIVERA NONE SUSPECTED NONE NONE
1 9 SAM RIVERA NONE TRUE NONE NONE
2 15 SAM RIVERA SIGNAL INCONSISTENCIES TRUE NONE NONE
3 2 JORDAN HAYES NONE SUSPECTED NONE NONE
4 6 JORDAN HAYES NONE SUSPECTED NONE NONE
description in_context
0 Sam Rivera is engaged in a fervent quest for a... True
1 Sam Rivera demonstrated technical expertise by... True
2 Sam Rivera identifies structured anomalies in ... True
3 Jordan Hayes is portrayed as skeptical of Tayl... True
4 Jordan Hayes is providing analytical insights ... True
问题生成¶
此函数接受用户查询列表并生成下一个候选问题。
输入[20]
已复制!
question_generator = LocalQuestionGen(
model=chat_model,
context_builder=context_builder,
tokenizer=tokenizer,
model_params=model_params,
context_builder_params=local_context_params,
)
question_generator = LocalQuestionGen( model=chat_model, context_builder=context_builder, tokenizer=tokenizer, model_params=model_params, context_builder_params=local_context_params, )
输入[21]
已复制!
question_history = [
"Tell me about Agent Mercer",
"What happens in Dulce military base?",
]
candidate_questions = await question_generator.agenerate(
question_history=question_history, context_data=None, question_count=5
)
print(candidate_questions.response)
question_history = [ "告诉我关于特工默瑟的事", "杜尔塞军事基地发生了什么?", ] candidate_questions = await question_generator.agenerate( question_history=question_history, context_data=None, question_count=5 ) print(candidate_questions.response)
Warning: No community records added when building community context.
Reached token limit - reverting to previous context state
['- What role does Agent Mercer play in the exploration of Dulce base?', '- How does Agent Mercer interact with other members of the team during Operation: Dulce?', '- What challenges does Agent Mercer face while investigating the secrets of Dulce base?', '- In what ways does Agent Mercer contribute to the success of the mission at Dulce base?', '- How does Agent Mercer’s relationship with the team influence the outcome of the operation at Dulce base?']