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
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_vectors import IndexSchema, LanceDBVectorStore
import os
import pandas as pd
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_vectors import IndexSchema, LanceDBVectorStore
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[2], line 17 13 from graphrag.query.structured_search.local_search.mixed_context import ( 14 LocalSearchMixedContext, 15 ) 16 from graphrag.query.structured_search.local_search.search import LocalSearch ---> 17 from graphrag_vectors import IndexSchema, LanceDBVectorStore ImportError: cannot import name 'LanceDBVectorStore' from 'graphrag_vectors' (/home/runner/work/graphrag/graphrag/packages/graphrag-vectors/graphrag_vectors/__init__.py)
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 = "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
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")
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(
index_schema=IndexSchema(index_name="default-entity-description")
)
description_embedding_store.connect(db_uri=LANCEDB_URI)
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")
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(
index_schema=IndexSchema(index_name="default-entity-description")
)
description_embedding_store.connect(db_uri=LANCEDB_URI)
print(f"Entity count: {len(entity_df)}")
entity_df.head()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 9 5 entities = read_indexer_entities(entity_df, community_df, COMMUNITY_LEVEL) 7 # load description embeddings to an in-memory lancedb vectorstore 8 # to connect to a remote db, specify url and port values. ----> 9 description_embedding_store = LanceDBVectorStore( 10 index_schema=IndexSchema(index_name="default-entity-description") 11 ) 12 description_embedding_store.connect(db_uri=LANCEDB_URI) 14 print(f"Entity count: {len(entity_df)}") NameError: name 'LanceDBVectorStore' is not defined
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: 107
Out[5]:
| id | human_readable_id | source | target | description | weight | combined_degree | text_unit_ids | |
|---|---|---|---|---|---|---|---|---|
| 0 | 7c9039f8-43d7-4685-a317-f7bbbfac8e3a | 0 | ALEX MERCER | PARANORMAL MILITARY SQUAD | Alex Mercer is a prominent agent and operative... | 17.0 | 29 | [ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc... |
| 1 | f0310841-7ad1-4286-8e1d-1641c180b3ab | 1 | TAYLOR CRUZ | PARANORMAL MILITARY SQUAD | Taylor Cruz is a leading agent in the Paranorm... | 9.0 | 29 | [ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc... |
| 2 | 84441d65-6f4e-40eb-92ef-743ac6d1229c | 2 | JORDAN HAYES | PARANORMAL MILITARY SQUAD | Dr. Jordan Hayes is a key member of the Parano... | 17.0 | 25 | [ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc... |
| 3 | ec2c0109-3a2f-479e-89d9-7a64abe07a63 | 3 | SAM RIVERA | PARANORMAL MILITARY SQUAD | Sam Rivera is a technical expert and agent wit... | 9.0 | 29 | [ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc... |
| 4 | 19d249b1-487e-4db9-85db-410cfb6ab986 | 4 | PARANORMAL MILITARY SQUAD | OPERATION: DULCE | The Paranormal Military Squad is the team assi... | 10.0 | 20 | [ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc... |
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: 41
Read community reports¶
In [7]:
Copied!
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"Report records: {len(report_df)}")
report_df.head()
Report records: 10
Out[7]:
| id | human_readable_id | community | level | parent | children | title | summary | full_content | rank | rating_explanation | findings | full_content_json | period | size | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 9785e64b429dacd70cce8238051f3438b387ebcd6920ef... | 7 | 7 | 1 | 0 | [] | Paranormal Military Squad and Operation Dulce | This community centers on the Paranormal Milit... | # Paranormal Military Squad and Operation Dulc... | 8.5 | The impact severity rating is high due to the ... | [{'explanation': 'The Paranormal Military Squa... | {\n "title": "Paranormal Military Squad and... | 2026-01-13 | 4 |
| 1 | 212c8ff1796bff731abe3d54f3216511ab15d5fb0d97eb... | 8 | 8 | 1 | 0 | [] | Paranormal Military Squad: Leadership and Scie... | This community centers on the Paranormal Milit... | # Paranormal Military Squad: Leadership and Sc... | 8.0 | The community poses a high impact due to its i... | [{'explanation': 'Taylor Cruz, often referred ... | {\n "title": "Paranormal Military Squad: Le... | 2026-01-13 | 3 |
| 2 | dbff99eaacade8ac4337a9bde0f533313445f0643ab3d0... | 9 | 9 | 1 | 0 | [] | Paranormal Military Squad and Operation: Dulce... | This community centers around the Paranormal M... | # Paranormal Military Squad and Operation: Dul... | 8.5 | The community poses a high impact severity due... | [{'explanation': 'The military complex is the ... | {\n "title": "Paranormal Military Squad and... | 2026-01-13 | 3 |
| 3 | b6e8ab1ac8ecc605bbec09ad78819b95ac08d62c5a9991... | 0 | 0 | 0 | -1 | [7, 8, 9] | Paranormal Military Squad and Operation: Dulce | This community centers on the Paranormal Milit... | # Paranormal Military Squad and Operation: Dul... | 8.5 | The community poses a high impact due to its e... | [{'explanation': 'Taylor Cruz is the central a... | {\n "title": "Paranormal Military Squad and... | 2026-01-13 | 10 |
| 4 | 97038bee58306d13b709b615fb2b816cae0c11273a9e73... | 1 | 1 | 0 | -1 | [] | Team of Agents Investigating Dulce Base | This community centers on a specialized team o... | # Team of Agents Investigating Dulce Base\n\nT... | 7.5 | The impact severity rating is high due to the ... | [{'explanation': 'The core of this community i... | {\n "title": "Team of Agents Investigating ... | 2026-01-13 | 5 |
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: 5
Out[8]:
| id | human_readable_id | text | n_tokens | document_id | entity_ids | relationship_ids | covariate_ids | |
|---|---|---|---|---|---|---|---|---|
| 0 | ff65e3e3764d360b35c55a83aaa35b0138af32551d0bc0... | 0 | # Operation: Dulce\n\n## Chapter 1\n\nThe thru... | 1200 | 6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a80... | [bbb2ad85-3d0b-4c26-b6f9-71ed76ee64bd, 66112f0... | [7c9039f8-43d7-4685-a317-f7bbbfac8e3a, f031084... | [4c6e019b-29c5-456c-951c-0cd3df308634, b2d2c91... |
| 1 | 56388c08c6e58a2aeaa235be38fe973bbdcbfb5ca72fd2... | 1 | Taylor offered a brief nod, perhaps too curt,... | 1200 | 6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a80... | [bbb2ad85-3d0b-4c26-b6f9-71ed76ee64bd, 66112f0... | [e15afdbb-6757-4f10-897d-54b9bb3dddc7, 319a7dc... | [9cdfde65-90c1-46a2-bfa2-9808ea4c821a, 83a704b... |
| 2 | 6012990fbcfad49511dce9a360dcc28d0c9bd37dc7b337... | 2 | team was descending into the earth, carrying ... | 1200 | 6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a80... | [bbb2ad85-3d0b-4c26-b6f9-71ed76ee64bd, 66112f0... | [4f42f1c3-b769-48f6-a01d-6a4a89b1c084, 319a7dc... | [d3d99801-1d52-4398-9e36-3dd3d8a06a56, 1a2f60a... |
| 3 | 402ae07f78c0154e8c24a93c00a90ee7c85e7478a755da... | 3 | Cruz squared their shoulders, clearly ruffled ... | 1200 | 6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a80... | [bbb2ad85-3d0b-4c26-b6f9-71ed76ee64bd, e1274d9... | [7c9039f8-43d7-4685-a317-f7bbbfac8e3a, 84441d6... | [b39dd61f-5a5a-4894-9047-23bee3e03f73, 23029bd... |
| 4 | 999a787eccebd488865de53a048f60889847f42057d5ad... | 4 | to him, and he couldn't help but feel the wei... | 382 | 6e81f882f89dd5596e1925dd3ae8a4f0a0edcb55b35a80... | [bbb2ad85-3d0b-4c26-b6f9-71ed76ee64bd, 66112f0... | [d3ea1355-14f3-494e-94cf-d43ac1077ab4, 72e568c... | [7c71874a-1443-40a6-bbad-6bc78ef23ee4, dac744e... |
In [9]:
Copied!
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)
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[9], line 1 ----> 1 from graphrag.config.enums import ModelType 2 from graphrag.config.models.language_model_config import LanguageModelConfig 3 from graphrag.language_model.manager import ModelManager ImportError: cannot import name 'ModelType' from 'graphrag.config.enums' (/home/runner/work/graphrag/graphrag/packages/graphrag/graphrag/config/enums.py)
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,
tokenizer=tokenizer,
)
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,
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[10], line 8 1 context_builder = LocalSearchMixedContext( 2 community_reports=reports, 3 text_units=text_units, 4 entities=entities, 5 relationships=relationships, 6 # if you did not run covariates during indexing, set this to None 7 covariates=covariates, ----> 8 entity_text_embeddings=description_embedding_store, 9 embedding_vectorstore_key=EntityVectorStoreKey.ID, # if the vectorstore uses entity title as ids, set this to EntityVectorStoreKey.TITLE 10 text_embedder=text_embedder, 11 tokenizer=tokenizer, 12 ) NameError: name 'description_embedding_store' is not defined
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)
}
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: 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,
}
In [12]:
Copied!
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="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
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[12], line 2 1 search_engine = LocalSearch( ----> 2 model=chat_model, 3 context_builder=context_builder, 4 tokenizer=tokenizer, 5 model_params=model_params, 6 context_builder_params=local_context_params, 7 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 8 ) NameError: name 'chat_model' is not defined
Run local search on sample queries¶
In [13]:
Copied!
result = await search_engine.search("Tell me about Agent Mercer")
print(result.response)
result = await search_engine.search("Tell me about Agent Mercer")
print(result.response)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[13], line 1 ----> 1 result = await search_engine.search("Tell me about Agent Mercer") 2 print(result.response) NameError: name 'search_engine' is not defined
In [14]:
Copied!
question = "Tell me about Dr. Jordan Hayes"
result = await search_engine.search(question)
print(result.response)
question = "Tell me about Dr. Jordan Hayes"
result = await search_engine.search(question)
print(result.response)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[14], line 2 1 question = "Tell me about Dr. Jordan Hayes" ----> 2 result = await search_engine.search(question) 3 print(result.response) NameError: name 'search_engine' is not defined
Inspecting the context data used to generate the response¶
In [15]:
Copied!
result.context_data["entities"].head()
result.context_data["entities"].head()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[15], line 1 ----> 1 result.context_data["entities"].head() NameError: name 'result' is not defined
In [16]:
Copied!
result.context_data["relationships"].head()
result.context_data["relationships"].head()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[16], line 1 ----> 1 result.context_data["relationships"].head() NameError: name 'result' is not defined
In [17]:
Copied!
if "reports" in result.context_data:
result.context_data["reports"].head()
if "reports" in result.context_data:
result.context_data["reports"].head()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[17], line 1 ----> 1 if "reports" in result.context_data: 2 result.context_data["reports"].head() NameError: name 'result' is not defined
In [18]:
Copied!
result.context_data["sources"].head()
result.context_data["sources"].head()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[18], line 1 ----> 1 result.context_data["sources"].head() NameError: name 'result' is not defined
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())
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[19], line 1 ----> 1 if "claims" in result.context_data: 2 print(result.context_data["claims"].head()) NameError: name 'result' is not defined
Question Generation¶
This function takes a list of user queries and generates the next candidate questions.
In [20]:
Copied!
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,
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[20], line 2 1 question_generator = LocalQuestionGen( ----> 2 model=chat_model, 3 context_builder=context_builder, 4 tokenizer=tokenizer, 5 model_params=model_params, 6 context_builder_params=local_context_params, 7 ) NameError: name 'chat_model' is not defined
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)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[21], line 5 1 question_history = [ 2 "Tell me about Agent Mercer", 3 "What happens in Dulce military base?", 4 ] ----> 5 candidate_questions = await question_generator.agenerate( 6 question_history=question_history, context_data=None, question_count=5 7 ) 8 print(candidate_questions.response) NameError: name 'question_generator' is not defined