Local Search
In [1]:
Copied!
# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License.
In [2]:
Copied!
import os
import pandas as pd
import tiktoken
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.input.loaders.dfs import (
store_entity_semantic_embeddings,
)
from graphrag.query.llm.oai.chat_openai import ChatOpenAI
from graphrag.query.llm.oai.embedding import OpenAIEmbedding
from graphrag.query.llm.oai.typing import OpenaiApiType
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
import tiktoken
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.input.loaders.dfs import (
store_entity_semantic_embeddings,
)
from graphrag.query.llm.oai.chat_openai import ChatOpenAI
from graphrag.query.llm.oai.embedding import OpenAIEmbedding
from graphrag.query.llm.oai.typing import OpenaiApiType
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
Local Search Example¶
Local search method generates answers by combining relevant data from the AI-extracted knowledge-graph with text chunks of the raw documents. This method is suitable for questions that require an understanding of specific entities mentioned in the documents (e.g. What are the healing properties of chamomile?).
Load text units and graph data tables as context for local search¶
- In this test we first load indexing outputs from parquet files to dataframes, then convert these dataframes into collections of data objects aligning with the knowledge model.
Load tables to dataframes¶
In [3]:
Copied!
INPUT_DIR = "./inputs/operation dulce"
LANCEDB_URI = f"{INPUT_DIR}/lancedb"
COMMUNITY_REPORT_TABLE = "create_final_community_reports"
ENTITY_TABLE = "create_final_nodes"
ENTITY_EMBEDDING_TABLE = "create_final_entities"
RELATIONSHIP_TABLE = "create_final_relationships"
COVARIATE_TABLE = "create_final_covariates"
TEXT_UNIT_TABLE = "create_final_text_units"
COMMUNITY_LEVEL = 2
INPUT_DIR = "./inputs/operation dulce"
LANCEDB_URI = f"{INPUT_DIR}/lancedb"
COMMUNITY_REPORT_TABLE = "create_final_community_reports"
ENTITY_TABLE = "create_final_nodes"
ENTITY_EMBEDDING_TABLE = "create_final_entities"
RELATIONSHIP_TABLE = "create_final_relationships"
COVARIATE_TABLE = "create_final_covariates"
TEXT_UNIT_TABLE = "create_final_text_units"
COMMUNITY_LEVEL = 2
Read entities¶
In [4]:
Copied!
# read nodes table to get community and degree data
entity_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_TABLE}.parquet")
entity_embedding_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_EMBEDDING_TABLE}.parquet")
entities = read_indexer_entities(entity_df, entity_embedding_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(
collection_name="entity_description_embeddings",
)
description_embedding_store.connect(db_uri=LANCEDB_URI)
entity_description_embeddings = store_entity_semantic_embeddings(
entities=entities, vectorstore=description_embedding_store
)
print(f"Entity count: {len(entity_df)}")
entity_df.head()
# read nodes table to get community and degree data
entity_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_TABLE}.parquet")
entity_embedding_df = pd.read_parquet(f"{INPUT_DIR}/{ENTITY_EMBEDDING_TABLE}.parquet")
entities = read_indexer_entities(entity_df, entity_embedding_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(
collection_name="entity_description_embeddings",
)
description_embedding_store.connect(db_uri=LANCEDB_URI)
entity_description_embeddings = store_entity_semantic_embeddings(
entities=entities, vectorstore=description_embedding_store
)
print(f"Entity count: {len(entity_df)}")
entity_df.head()
Entity count: 434
[2024-10-24T17:21:23Z WARN lance::dataset] No existing dataset at /home/runner/work/graphrag/graphrag/docs/examples_notebooks/inputs/operation dulce/lancedb/entity_description_embeddings.lance, it will be created
Out[4]:
| level | title | type | description | source_id | community | degree | human_readable_id | id | size | graph_embedding | entity_type | top_level_node_id | x | y | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | ALEX MERCER | PERSON | Alex Mercer is a character with a military bac... | 00fafabae48948779fee2afe600f5143,1e433d6b30887... | 1 | 9 | 0 | b45241d70f0e43fca764df95b2b81f77 | 9 | None | None | b45241d70f0e43fca764df95b2b81f77 | 0 | 0 |
| 1 | 0 | TAYLOR CRUZ | PERSON | Taylor Cruz is a character who plays a pivotal... | 00fafabae48948779fee2afe600f5143,1e433d6b30887... | 1 | 12 | 1 | 4119fd06010c494caa07f439b333f4c5 | 12 | None | None | 4119fd06010c494caa07f439b333f4c5 | 0 | 0 |
| 2 | 0 | JORDAN HAYES | PERSON | Dr. Jordan Hayes is a key character in a narra... | 00fafabae48948779fee2afe600f5143,2cf7a230c367a... | 1 | 9 | 2 | d3835bf3dda84ead99deadbeac5d0d7d | 9 | None | None | d3835bf3dda84ead99deadbeac5d0d7d | 0 | 0 |
| 3 | 0 | SAM RIVERA | PERSON | Sam Rivera is a character renowned for their t... | 00fafabae48948779fee2afe600f5143,1e433d6b30887... | 1 | 15 | 3 | 077d2820ae1845bcbb1803379a3d1eae | 15 | None | None | 077d2820ae1845bcbb1803379a3d1eae | 0 | 0 |
| 4 | 0 | PARANORMAL MILITARY SQUAD | ORGANIZATION | The Paranormal Military Squad is an elite clan... | 00fafabae48948779fee2afe600f5143,1e433d6b30887... | 1 | 14 | 4 | 3671ea0dd4e84c1a9b02c5ab2c8f4bac | 14 | None | None | 3671ea0dd4e84c1a9b02c5ab2c8f4bac | 0 | 0 |
Read relationships¶
In [5]:
Copied!
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"Relationship count: {len(relationship_df)}")
relationship_df.head()
Relationship count: 276
Out[5]:
| source | target | weight | description | text_unit_ids | id | human_readable_id | source_degree | target_degree | rank | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | ALEX MERCER | TAYLOR CRUZ | 7.0 | Alex Mercer and Taylor Cruz are integral membe... | [00fafabae48948779fee2afe600f5143, 1e433d6b308... | b35c3d1a7daa4924b6bdb58bc69c354d | 0 | 9 | 12 | 21 |
| 1 | ALEX MERCER | TAYLOR CRUZ | 7.0 | Alex Mercer and Taylor Cruz are integral membe... | [00fafabae48948779fee2afe600f5143, 1e433d6b308... | b35c3d1a7daa4924b6bdb58bc69c354d | 0 | 9 | 12 | 21 |
| 2 | ALEX MERCER | TAYLOR CRUZ | 7.0 | Alex Mercer and Taylor Cruz are integral membe... | [00fafabae48948779fee2afe600f5143, 1e433d6b308... | b35c3d1a7daa4924b6bdb58bc69c354d | 0 | 9 | 12 | 21 |
| 3 | ALEX MERCER | TAYLOR CRUZ | 7.0 | Alex Mercer and Taylor Cruz are integral membe... | [00fafabae48948779fee2afe600f5143, 1e433d6b308... | b35c3d1a7daa4924b6bdb58bc69c354d | 0 | 9 | 12 | 21 |
| 4 | ALEX MERCER | JORDAN HAYES | 6.0 | Alex Mercer and Jordan Hayes are colleagues wh... | [00fafabae48948779fee2afe600f5143, 2cf7a230c36... | a97e2ecd870944cfbe71c79bc0fcc752 | 1 | 9 | 9 | 18 |
In [6]:
Copied!
# 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}
# 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}
Claim records: 89
Read community reports¶
In [7]:
Copied!
report_df = pd.read_parquet(f"{INPUT_DIR}/{COMMUNITY_REPORT_TABLE}.parquet")
reports = read_indexer_reports(report_df, entity_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, entity_df, COMMUNITY_LEVEL)
print(f"Report records: {len(report_df)}")
report_df.head()
Report records: 6
Out[7]:
| community | full_content | level | rank | title | rank_explanation | summary | findings | full_content_json | id | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 4 | # Dulce Base and the Paranormal Military Squad... | 1 | 8.5 | Dulce Base and the Paranormal Military Squad: ... | The impact severity rating is high due to the ... | The community is centered around Dulce Base, a... | [{'explanation': 'Dulce Base is the primary lo... | {\n "title": "Dulce Base and the Paranormal... | 6f8ba6b6-506e-46c1-83ce-982d59622554 |
| 1 | 5 | # Sam Rivera and the Paranormal Military Squad... | 1 | 7.5 | Sam Rivera and the Paranormal Military Squad a... | The impact severity rating is high due to the ... | The community is centered around Sam Rivera, a... | [{'explanation': 'Sam Rivera is recognized for... | {\n "title": "Sam Rivera and the Paranormal... | 418f4536-d673-4212-8a7c-ca1aac547d0f |
| 2 | 0 | # Dulce Base and the Paranormal Military Squad... | 0 | 8.5 | Dulce Base and the Paranormal Military Squad Team | The impact severity rating is high due to the ... | Dulce Base serves as the operational hub for t... | [{'explanation': 'The Paranormal Military Squa... | {\n "title": "Dulce Base and the Paranormal... | 251df57e-fd49-49a7-b262-ccaff95d7a51 |
| 3 | 1 | # Dulce Base and the Paranormal Military Squad... | 0 | 8.5 | Dulce Base and the Paranormal Military Squad: ... | The impact severity rating is high due to the ... | The community is centered around Dulce Base, a... | [{'explanation': 'Sam Rivera is recognized for... | {\n "title": "Dulce Base and the Paranormal... | 6e536385-8056-4a82-8670-c0ccaf007fb4 |
| 4 | 2 | # Dulce Base: Extraterrestrial Research and Co... | 0 | 8.5 | Dulce Base: Extraterrestrial Research and Comm... | The impact severity rating is high due to the ... | Dulce Base is a highly classified facility in ... | [{'explanation': 'Dulce Base is the epicenter ... | {\n "title": "Dulce Base: Extraterrestrial ... | 660c8fba-b65f-4fcd-9c98-203600cf1981 |
Read text units¶
In [8]:
Copied!
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"Text unit records: {len(text_unit_df)}")
text_unit_df.head()
Text unit records: 12
Out[8]:
| id | text | n_tokens | document_ids | entity_ids | relationship_ids | covariate_ids | |
|---|---|---|---|---|---|---|---|
| 0 | 2cf7a230c367a2dfaf0fc3c903eb8948 | # Operation: Dulce\n\n## Chapter 1\n\nThe thru... | 2500 | [958fdd043f17ade63cb13570b59df295] | [b45241d70f0e43fca764df95b2b81f77, 4119fd06010... | [b35c3d1a7daa4924b6bdb58bc69c354d, a97e2ecd870... | [ad5a2020-cdec-4982-acdf-dbe5ee530066, 9d8a0fe... |
| 1 | 6d1255303acb7c9dc951cb0f5fc3042c | be the same.\n\n\*\n\nThe sense of foreboding... | 2500 | [958fdd043f17ade63cb13570b59df295] | [b45241d70f0e43fca764df95b2b81f77, 4119fd06010... | [b35c3d1a7daa4924b6bdb58bc69c354d, a97e2ecd870... | [5d1c9126-c48d-4755-9f9c-f739c823f95f, ec64a42... |
| 2 | e841f178310356740b2ee9101d12c97f | . "Your take on these signal inconsistencies?"... | 2500 | [958fdd043f17ade63cb13570b59df295] | [b45241d70f0e43fca764df95b2b81f77, 4119fd06010... | [b35c3d1a7daa4924b6bdb58bc69c354d, a97e2ecd870... | [0b22a34b-32e9-46a4-a0e8-d3d5466eba15, 7e14972... |
| 3 | f36d96862b9366d7240b5c7ceb04f12b | , absorbed in the bewilderment of contact, whi... | 2500 | [958fdd043f17ade63cb13570b59df295] | [b45241d70f0e43fca764df95b2b81f77, 4119fd06010... | [b35c3d1a7daa4924b6bdb58bc69c354d, 09f18f81442... | [9cd6d645-ab97-4b39-b02e-647cea9b5545, 50dc124... |
| 4 | f7d43808d2fb452cd953bf50c6de6bd4 | were at once coherent and enigmatic: "*Voyage... | 2500 | [958fdd043f17ade63cb13570b59df295] | [b45241d70f0e43fca764df95b2b81f77, 4119fd06010... | [e02be3e37ca0454883a4c1fd859c24bb, 1dbc51475cb... | [87cf5900-6211-4e04-9115-50f3617c88b4] |
In [9]:
Copied!
api_key = os.environ["GRAPHRAG_API_KEY"]
llm_model = os.environ["GRAPHRAG_LLM_MODEL"]
embedding_model = os.environ["GRAPHRAG_EMBEDDING_MODEL"]
llm = ChatOpenAI(
api_key=api_key,
model=llm_model,
api_type=OpenaiApiType.OpenAI, # OpenaiApiType.OpenAI or OpenaiApiType.AzureOpenAI
max_retries=20,
)
token_encoder = tiktoken.get_encoding("cl100k_base")
text_embedder = OpenAIEmbedding(
api_key=api_key,
api_base=None,
api_type=OpenaiApiType.OpenAI,
model=embedding_model,
deployment_name=embedding_model,
max_retries=20,
)
api_key = os.environ["GRAPHRAG_API_KEY"]
llm_model = os.environ["GRAPHRAG_LLM_MODEL"]
embedding_model = os.environ["GRAPHRAG_EMBEDDING_MODEL"]
llm = ChatOpenAI(
api_key=api_key,
model=llm_model,
api_type=OpenaiApiType.OpenAI, # OpenaiApiType.OpenAI or OpenaiApiType.AzureOpenAI
max_retries=20,
)
token_encoder = tiktoken.get_encoding("cl100k_base")
text_embedder = OpenAIEmbedding(
api_key=api_key,
api_base=None,
api_type=OpenaiApiType.OpenAI,
model=embedding_model,
deployment_name=embedding_model,
max_retries=20,
)
Create local search context builder¶
In [10]:
Copied!
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,
token_encoder=token_encoder,
)
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,
token_encoder=token_encoder,
)
Create local search engine¶
In [11]:
Copied!
# 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)
}
llm_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: 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)
}
llm_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,
}
In [12]:
Copied!
search_engine = LocalSearch(
llm=llm,
context_builder=context_builder,
token_encoder=token_encoder,
llm_params=llm_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(
llm=llm,
context_builder=context_builder,
token_encoder=token_encoder,
llm_params=llm_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
)
Run local search on sample queries¶
In [13]:
Copied!
result = await search_engine.asearch("Tell me about Agent Mercer")
print(result.response)
result = await search_engine.asearch("Tell me about Agent Mercer")
print(result.response)
### Overview of Agent Alex Mercer Agent Alex Mercer is a central figure within the Paranormal Military Squad Team at Dulce Base, where he plays a pivotal role in the team's operations and mission objectives. His responsibilities are multifaceted, encompassing leadership, strategic oversight, and direct involvement in the analysis and interpretation of extraterrestrial signals. Mercer's military background and experience are crucial to his role, as he guides the team through complex scenarios involving potential first contact with alien intelligence [Data: Entities (0, 209); Relationships (5, 8, 65)]. ### Leadership and Responsibilities As a leader, Alex Mercer is instrumental in overseeing the team's efforts to engage with extraterrestrial intelligence. His role involves ensuring a cautious and strategic approach to interspecies communication, which is vital for the success of their mission. Mercer's leadership is characterized by a mix of concern and anticipation, reflecting the gravity of the mission at hand. He is responsible for guiding the team's response to extraterrestrial contact, ensuring that the engagement is handled with care and foresight [Data: Entities (0); Relationships (5, 8, 6)]. ### Collaboration and Team Dynamics Agent Mercer works closely with other key members of the Paranormal Military Squad, such as Dr. Jordan Hayes and Sam Rivera. His collaboration with Dr. Hayes is particularly significant, as they jointly focus on decrypting and communicating with extraterrestrial intelligence. This partnership is built on mutual respect and recognition of each other's analytical skills, which are essential for the team's success. Mercer's interactions with Sam Rivera highlight his role as a mentor, providing guidance and fostering a relationship based on intuition and trust [Data: Reports (0); Relationships (1, 4, 2)]. ### Involvement in Extraterrestrial Communication Mercer's involvement in the decryption and analysis of alien signals is a critical aspect of his role. He is actively engaged in interpreting these signals, contributing to the understanding of an extraterrestrial society. His efforts are not only focused on overseeing the team but also on unraveling galactic mysteries and engaging with alien signals. This involvement underscores his position as a key figure in the mission's hypothesis and decision-making processes [Data: Claims (73, 85, 82); Reports (0)]. In summary, Agent Alex Mercer is a vital member of the Paranormal Military Squad Team, whose leadership and expertise are crucial to the team's mission at Dulce Base. His role in guiding the team through the complexities of extraterrestrial communication and his collaboration with other team members highlight his importance in the broader objectives of their work.
In [14]:
Copied!
question = "Tell me about Dr. Jordan Hayes"
result = await search_engine.asearch(question)
print(result.response)
question = "Tell me about Dr. Jordan Hayes"
result = await search_engine.asearch(question)
print(result.response)
### Overview of Dr. Jordan Hayes Dr. Jordan Hayes is a prominent member of the Paranormal Military Squad, a specialized team based at Dulce Base, dedicated to the study and communication with extraterrestrial entities. Dr. Hayes plays a crucial role in the team's mission, focusing on deciphering alien code and interpreting extraterrestrial patterns. This expertise is vital to the squad's efforts in understanding and interacting with alien intelligence [Data: Entities (104, 2); Reports (0)]. ### Role and Responsibilities Dr. Hayes is deeply involved in the analysis and interpretation of alien signals, which includes isolating signal harmonics, decrypting alien messages, and interpreting these signals for further analysis. This work is central to the team's operations at Dulce Base, where Dr. Hayes collaborates closely with other team members, such as Agent Alex Mercer, to manage interspecies communication [Data: Entities (2, 166, 192); Relationships (1, 4, 26, 67)]. ### Expertise and Approach Known for an analytical and skeptical mindset, Dr. Hayes emphasizes empirical evidence and adaptability in the face of the unknown. This approach is particularly evident in their work on decryption algorithms and signal analysis, which are crucial for deciphering extraterrestrial communications. Dr. Hayes' role is pivotal in the team's focus on analyzing and interpreting alien signals, which is a cornerstone of their operation at Dulce Base [Data: Entities (2, 180, 124); Claims (12, 54, 68)]. ### Collaboration and Impact Dr. Hayes works closely with colleagues such as Sam Rivera and Taylor Cruz, contributing to the team's collective effort in deciphering alien code and preparing for first contact. The collaboration with Agent Alex Mercer is particularly significant, as they share a mutual respect and understanding of each other's strengths and the mission's significance. This teamwork is essential for the success of their mission, as they bring their expertise to the forefront of paranormal military endeavors [Data: Reports (0); Relationships (21, 9, 1, 4, 67)]. ### Significance of Work The work of Dr. Hayes and the Paranormal Military Squad is not just about scientific discovery but also about preparing humanity for potential interstellar communication. The team's efforts in analyzing extraterrestrial patterns and first contact data are indicative of their role in predicting extraterrestrial intentions and actions. Dr. Hayes' contributions are crucial in this historic effort, which could mark the beginning of a new era in human-alien relations [Data: Reports (0); Claims (84, 54, 61)]. In summary, Dr. Jordan Hayes is a key figure in the Paranormal Military Squad, bringing a critical and methodical approach to the team's extraordinary endeavors in understanding and interacting with alien entities. Their work at Dulce Base is central to the mission of deciphering extraterrestrial signals and preparing for potential interspecies communication.
Inspecting the context data used to generate the response¶
In [15]:
Copied!
result.context_data["entities"].head()
result.context_data["entities"].head()
Out[15]:
| id | entity | description | number of relationships | in_context | |
|---|---|---|---|---|---|
| 0 | 104 | DR. JORDAN HAYES | Dr. Jordan Hayes is a member of the Paranormal... | 7 | True |
| 1 | 153 | EXPERTISE | The specialized knowledge or skill that team m... | 0 | True |
| 2 | 2 | JORDAN HAYES | Dr. Jordan Hayes is a key character in a narra... | 9 | True |
| 3 | 148 | DATA ANALYSIS | The process of examining and interpreting info... | 0 | True |
| 4 | 140 | STAR ALIGNMENTS | Celestial configurations that Dr. Jordan Hayes... | 0 | True |
In [16]:
Copied!
result.context_data["relationships"].head()
result.context_data["relationships"].head()
Out[16]:
| id | source | target | description | weight | rank | links | in_context | |
|---|---|---|---|---|---|---|---|---|
| 0 | 21 | JORDAN HAYES | SAM RIVERA | Jordan Hayes and Sam Rivera are colleagues at ... | 5.0 | 24 | 2 | True |
| 1 | 22 | JORDAN HAYES | PARANORMAL MILITARY SQUAD | Jordan Hayes is a member of the Paranormal Mil... | 5.0 | 23 | 2 | True |
| 2 | 34 | SAM RIVERA | DR. JORDAN HAYES | Dr. Jordan Hayes and Sam Rivera are colleagues... | 1.0 | 22 | 2 | True |
| 3 | 9 | TAYLOR CRUZ | JORDAN HAYES | Taylor Cruz and Jordan Hayes are both integral... | 6.0 | 21 | 2 | True |
| 4 | 40 | PARANORMAL MILITARY SQUAD | DR. JORDAN HAYES | Dr. Jordan Hayes is a key member of the Parano... | 2.0 | 21 | 2 | True |
In [17]:
Copied!
result.context_data["reports"].head()
result.context_data["reports"].head()
Out[17]:
| id | title | content | |
|---|---|---|---|
| 0 | 0 | Dulce Base and the Paranormal Military Squad Team | # Dulce Base and the Paranormal Military Squad... |
In [18]:
Copied!
result.context_data["sources"].head()
result.context_data["sources"].head()
Out[18]:
| id | text | |
|---|---|---|
| 0 | 5 | the universe.\n\nIn a symphony of clicks and ... |
| 1 | 11 | , the sentinel within them ever alert.\n\nAlex... |
| 2 | 3 | , absorbed in the bewilderment of contact, whi... |
In [19]:
Copied!
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 12 DR. JORDAN HAYES NONE TRUE NONE NONE
1 13 DR. JORDAN HAYES NONE SUSPECTED NONE NONE
2 18 DR. JORDAN HAYES ALEX TRUE NONE NONE
3 49 DR. JORDAN HAYES NONE SUSPECTED NONE NONE
4 74 DR. JORDAN HAYES NONE SUSPECTED NONE NONE
description in_context
0 Dr. Jordan Hayes contemplates their skepticism... True
1 Dr. Jordan Hayes mused over the layers of data... True
2 Dr. Jordan Hayes and Alex discovered a panel h... True
3 Dr. Jordan Hayes was focused on deciphering al... True
4 Dr. Jordan Hayes is analyzing the evolving ali... True
Question Generation¶
This function takes a list of user queries and generates the next candidate questions.
In [20]:
Copied!
question_generator = LocalQuestionGen(
llm=llm,
context_builder=context_builder,
token_encoder=token_encoder,
llm_params=llm_params,
context_builder_params=local_context_params,
)
question_generator = LocalQuestionGen(
llm=llm,
context_builder=context_builder,
token_encoder=token_encoder,
llm_params=llm_params,
context_builder_params=local_context_params,
)
In [21]:
Copied!
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 = [
"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)
['- What is the role of Agent Alex Mercer in Operation: Dulce?', '- How does the Paranormal Military Squad interact with extraterrestrial intelligence at Dulce Base?', '- What are the main objectives of Operation: Dulce at the Dulce Military Base?', '- How does the environment of the Dulce Military Base affect the team members involved in the operation?', "- What is the significance of New Mexico's location for the Dulce Military Base and Operation: Dulce?"]