A Practical GraphRAG Architecture Using LangExtract, Neo4j, Qdrant, and Ollama使用 LangExtract、Neo4j、Qdrant 和 Ollama 构建实用的 GraphRAG 架构
M K Pavan KumarM K Pavan Kumar
Today, we are going to build a complete GraphRAG system using 100% local LLMs powered by Ollama, Neo4j, Qdrant, and LangExtract. Unlike traditional RAG systems that retrieve document chunks, this architecture transforms raw text into a knowledge graph and retrieves semantically relevant entities connected through relationships. The real highlight of this solution is LangExtract, which automatically extracts entities and relationships from unstructured text and converts them into graph-ready knowledge. By combining vector retrieval from Qdrant with graph traversal in Neo4j, we create a retrieval pipeline that understands both meaning and context. Let’s dive into the architecture and see how each component works together to deliver graph-grounded answers.今天,我们将使用 100% 本地 LLM 构建一个完整的 GraphRAG 系统,该系统由 Ollama、Neo4j、Qdrant 和 LangExtract 提供支持。与检索文档块的传统 RAG 系统不同,此架构将原始文本转换为知识图谱,并检索通过关系连接的语义相关的实体。此解决方案的真正亮点是 LangExtract,它可以自动从非结构化文本中提取实体和关系,并将它们转换为图谱就绪的知识。通过将 Qdrant 的向量检索与 Neo4j 的图遍历相结合,我们创建了一个理解含义和上下文的检索管道。让我们深入了解该架构,看看每个组件如何协同工作以提供基于图谱的答案。

Architecture Deep Dive架构深入解析
The architecture begins with unstructured raw text entering the LangExtract layer. Unlike conventional RAG pipelines that immediately split documents into chunks and generate embeddings, this system first transforms the text into structured knowledge. LangExtract, powered by an Ollama-hosted language model, identifies entities and their semantic relationships directly from the source text. In the medication example, entities such as medications, dosages, frequencies, and medical conditions are extracted while preserving their relationships through a common grouping mechanism. This stage effectively converts natural language into a structured representation that captures factual connections rather than merely storing text passages.该架构始于进入 LangExtract 层的不结构化原始文本。与传统 RAG 管道立即将文档拆分成块并生成嵌入不同,该系统首先将文本转换为结构化知识。由 Ollama 托管的语言模型驱动的 LangExtract 直接从源文本中识别实体及其语义关系。在药物示例中,提取了药物、剂量、频率和病症等实体,同时通过通用的分组机制保留了它们之间的关系。此阶段有效地将自然语言转换为结构化表示,该表示捕获事实连接,而不仅仅是存储文本片段。
Once extraction is complete, the generated entities and relationships are transformed into graph components. Every extracted concept becomes a graph node with a unique identifier, while semantic relationships such as dosage, frequency, or condition become explicit edges connecting those nodes. This conversion process creates a formal knowledge representation where information is organized around entities and their relationships instead of document boundaries. The graph structure preserves contextual meaning that would normally be lost in traditional chunk-based retrieval systems.提取完成后,生成的实体和关系将转换为图谱组件。每个提取的概念都成为一个具有唯一标识符的图节点,而剂量、频率或病症等语义关系则成为连接这些节点的显式边。此转换过程创建了一个正式的知识表示,其中信息围绕实体及其关系进行组织,而不是围绕文档边界。图结构保留了在传统基于块的检索系统中通常会丢失的上下文含义。
The extracted graph is then ingested into Neo4j, which serves as the system’s primary knowledge repository. Each entity is stored as a graph node, and each semantic relationship is stored as a native graph edge. Neo4j becomes the authoritative source of structured knowledge and enables efficient traversal across connected concepts. Rather than retrieving isolated text snippets, the system can later explore multi-hop relationships between entities, allowing it to uncover contextual information that extends beyond the original extraction point.然后将提取的图谱摄取到 Neo4j 中,Neo4j 作为系统的主要知识库。每个实体都存储为图节点,每个语义关系都存储为原生图边。Neo4j 成为结构化知识的权威来源,并支持跨连接概念的高效遍历。系统可以探索实体之间的多跳关系,而不是检索孤立的文本片段,从而能够发现超出原始提取点的上下文信息。
After graph construction, the architecture generates embeddings for every graph node. Instead of embedding entire documents or chunks, the embedding model operates directly on entity names and concepts. Each entity receives a vector representation that captures its semantic meaning in embedding space. This design choice creates a semantic index over graph entities rather than textual content, enabling retrieval to focus on concepts rather than passages.在图谱构建之后,为每个图节点生成嵌入。嵌入模型直接在实体名称和概念上运行,而不是嵌入整个文档或块。每个实体都会获得一个向量表示,该表示在嵌入空间中捕获其语义含义。此设计选择在图实体而不是文本内容上创建语义索引,从而使检索能够专注于概念而不是文本片段。
These entity embeddings are then stored in Qdrant alongside their corresponding Neo4j node identifiers. Qdrant functions as a high-performance semantic retrieval layer, while Neo4j remains the structured knowledge layer. The payload stored in Qdrant contains the Neo4j node ID, creating a direct mapping between vector search results and graph entities. This separation of responsibilities allows Qdrant to excel at semantic similarity search while Neo4j handles relationship traversal and graph reasoning.这些实体嵌入然后与相应的 Neo4j 节点标识符一起存储在 Qdrant 中。Qdrant 作为高性能语义检索层,而 Neo4j 仍然是结构化知识层。存储在 Qdrant 中的有效负载包含 Neo4j 节点 ID,从而在向量搜索结果和图实体之间建立直接映射。这种职责分离使 Qdrant 在语义相似性搜索方面表现出色,而 Neo4j 则处理关系遍历和图谱推理。
During query time, a user submits a natural language question. The same embedding model converts the query into a vector representation. This query embedding is then searched against Qdrant to identify the most semantically relevant graph entities. Unlike traditional RAG systems that return document chunks, the retrieval process returns node identifiers corresponding to entities within the knowledge graph. These nodes act as semantic entry points into the graph and represent the concepts most closely related to the user’s intent.在查询时,用户会提交一个自然语言问题。相同的嵌入模型将查询转换为向量表示。然后,此查询嵌入会针对 Qdrant 进行搜索,以识别最相关的图实体。与返回文档块的传统 RAG 系统不同,检索过程返回知识图谱中实体的节点标识符。这些节点充当图谱的语义入口点,并代表与用户意图最接近的概念。
The retrieved node identifiers are subsequently used to query Neo4j. Rather than stopping at the retrieved entities, the system performs graph expansion by traversing neighboring nodes and relationships. This traversal retrieves a relevant subgraph containing both the matched entities and their connected context. The expansion process allows the architecture to gather supporting information that may not have been directly retrieved through vector similarity alone. As a result, the retrieved context contains both semantic relevance and structural relationships.检索到的节点标识符随后用于查询 Neo4j。系统不是停留在检索到的实体上,而是通过遍历相邻节点和关系来执行图谱扩展。此遍历会检索包含匹配实体及其连接上下文的相关子图谱。扩展过程允许架构收集仅通过向量相似性无法直接检索到的支持信息。因此,检索到的上下文同时包含语义相关性和结构化关系。
The resulting subgraph is then transformed into a format suitable for language model consumption. Nodes are collected into a structured list, while relationships are converted into readable triples that express explicit connections between entities. For example, relationships such as “Lisinopril dosage 10mg” or “Metformin condition diabetes” become structured contextual statements. This formatting stage bridges the gap between graph databases and language models by converting graph structures into interpretable textual context.然后将生成的子图谱转换为适合语言模型使用的格式。节点被收集到一个结构化列表中,而关系则转换为可读的三元组,以表达实体之间的显式连接。例如,“Lisinopril 剂量 10mg”或“Metformin 病症 糖尿病”等关系将成为结构化的上下文语句。此格式化阶段通过将图结构转换为可解释的文本上下文,弥合了图数据库和语言模型之间的差距。
Finally, the formatted graph context is provided to the LLM. Instead of relying on retrieved document chunks, the model receives a graph-grounded representation consisting of entities and relationships. This enables the LLM to reason over explicit facts and connections rather than inferring relationships from fragmented text passages. Because the context originates from graph traversal, the model gains access to structured knowledge that is inherently more explainable and traceable than standard vector-based retrieval.最后,将格式化的图谱上下文提供给 LLM。模型接收基于图谱的表示,而不是依赖检索到的文档块,该表示由实体和关系组成。这使得 LLM 能够推理显式事实和连接,而不是从零散的文本片段推断关系。由于上下文源自图谱遍历,因此模型可以访问比标准基于向量的检索更具可解释性和可追溯性的结构化知识。
The overall architecture can therefore be viewed as a hybrid retrieval system where LangExtract performs knowledge extraction, Neo4j manages structured relationships, Qdrant provides semantic entity retrieval, and the LLM performs graph-grounded reasoning. The combination of vector similarity and graph traversal creates a retrieval mechanism that is both semantically aware and structurally informed, allowing the system to answer questions using connected knowledge rather than isolated text fragments. This approach significantly improves the retrieval of relational information and makes it particularly effective for domains such as healthcare, finance, legal systems, enterprise knowledge management, and scientific research where understanding relationships between entities is often more important than retrieving individual passages of text.因此,整个架构可以被视为一种混合检索系统,其中 LangExtract 执行知识提取,Neo4j 管理结构化关系,Qdrant 提供语义实体检索,LLM 执行基于图谱的推理。向量相似性和图谱遍历的结合创建了一种既具有语义意识又具有结构感知的检索机制,使系统能够使用连接的知识而不是孤立的文本片段来回答问题。这种方法显著提高了关系信息的检索能力,并且对于医疗保健、金融、法律系统、企业知识管理和科学研究等领域特别有效,在这些领域,理解实体之间的关系通常比检索单个文本片段更重要。
Implementation Walkthrough实现演练
__init__()__init__()
The constructor serves as the entry point for the entire GraphRAG system. It loads all required configuration values such as Neo4j credentials, Qdrant connection details, and Ollama settings from environment variables. The method establishes connections to both Neo4j and Qdrant so they can be reused throughout the pipeline. It also initializes the Ollama client that will be used for entity extraction, embedding generation, and answer synthesis. Finally, it stores model names and vector dimensions, allowing the architecture to remain flexible and configurable.构造函数是整个 GraphRAG 系统的入口点。它从环境变量加载所有必需的配置值,例如 Neo4j 凭据、Qdrant 连接详细信息和 Ollama 设置。该方法建立与 Neo4j 和 Qdrant 的连接,以便在整个管道中重复使用它们。它还初始化将用于实体提取、嵌入生成和答案合成的 Ollama 客户端。最后,它存储模型名称和向量维度,从而使架构保持灵活和可配置。
def __init__(self,env_path: str = ".env",ollama_model_extract: str = "gemma3:latest",
ollama_model_answer: str = "gemma3:latest",ollama_embedding_model: str = "embeddinggemma:latest",
ollama_host: str | None = None,vector_dimension: int = 768,
):
load_dotenv(env_path)
self.qdrant_key = os.getenv("QDRANT_KEY")
self.qdrant_url = os.getenv("QDRANT_URL")
self.neo4j_uri = os.getenv("NEO4J_URI")
self.neo4j_username = os.getenv("NEO4J_USERNAME")
self.neo4j_password = os.getenv("NEO4J_PASSWORD")
self.neo4j_driver = GraphDatabase.driver(
self.neo4j_uri, auth=(self.neo4j_username, self.neo4j_password)
)
self.qdrant_client = QdrantClient(
url=self.qdrant_url,
api_key=self.qdrant_key,
)
# Ollama client for local embeddings (embeddinggemma:latest)
self.ollama_client = ollama.Client(host=ollama_host) if ollama_host else ollama.Client()
# langextract needs a plain URL string, not a client object
self.ollama_url = ollama_host or os.environ.get("OLLAMA_HOST", "http://localhost:11434")
# Model / config knobs
self.ollama_model_extract = ollama_model_extract
self.ollama_model_answer = ollama_model_answer
self.ollama_embedding_model = ollama_embedding_model
self.vector_dimension = vector_dimensionextract_graph_components()extract_graph_components()
This method is responsible for converting raw unstructured text into structured knowledge. It defines extraction instructions and provides examples that guide LangExtract in identifying entities and their relationships. Using an Ollama-hosted LLM, LangExtract processes the input text and extracts concepts such as medications, dosages, frequencies, and conditions. The output at this stage is still a collection of extracted elements rather than a graph. The method then forwards these extractions for graph construction, creating the foundation for the knowledge graph.此方法负责将原始非结构化文本转换为结构化知识。它定义了提取指令,并提供了指导 LangExtract 识别实体及其关系的示例。使用 Ollama 托管的 LLM,LangExtract 处理输入文本并提取药物、剂量、频率和病症等概念。此阶段的输出仍然是提取元素的集合,而不是图谱。然后,该方法将这些提取内容转发给图谱构建,为知识图谱奠定基础。
def extract_graph_components(self, raw_data: str):
"""Extract medication entities and relationships using langextract + Ollama."""
prompt_description = textwrap.dedent("""
Extract medications with their details, using attributes to group related information:
1. Extract entities in the order they appear in the text
2. Each entity must have a 'medication_group' attribute linking it to its medication
3. All details about a medication should share the same medication_group value
""").strip()
examples = [
lx.data.ExampleData(
text=(
"Patient takes Aspirin 100mg daily for heart health and"
" Simvastatin 20mg at bedtime."
),
extractions=[
lx.data.Extraction(
extraction_class="medication",
extraction_text="Aspirin",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="dosage",
extraction_text="100mg",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="frequency",
extraction_text="daily",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="condition",
extraction_text="heart health",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="medication",
extraction_text="Simvastatin",
attributes={"medication_group": "Simvastatin"},
),
lx.data.Extraction(
extraction_class="dosage",
extraction_text="20mg",
attributes={"medication_group": "Simvastatin"},
),
lx.data.Extraction(
extraction_class="frequency",
extraction_text="at bedtime",
attributes={"medication_group": "Simvastatin"},
),
],
)
]
result = lx.extract(
text_or_documents=raw_data,
prompt_description=prompt_description,
examples=examples,
model_id=self.ollama_model_extract,
model_url=self.ollama_url,
resolver_params={"format_handler": lx_ollama.OLLAMA_FORMAT_HANDLER},
max_char_buffer=4000,
show_progress=True,
)
return self._convert_extractions_to_graph(result.extractions)_convert_extractions_to_graph()_convert_extractions_to_graph()
Once entities are extracted, this method transforms them into a graph-friendly structure. It groups related information together and identifies the primary entity that acts as the anchor node. Unique identifiers are generated for every node to ensure consistency across Neo4j and Qdrant. Relationships are then created between anchor entities and their associated attributes, preserving semantic meaning. The final output consists of graph nodes and edges that are ready for ingestion into a graph database.提取实体后,此方法将其转换为对图谱友好的结构。它将相关信息分组在一起,并识别充当锚节点的首要实体。为每个节点生成唯一标识符,以确保 Neo4j 和 Qdrant 之间的一致性。然后,在锚实体及其关联属性之间创建关系,以保留语义含义。最终输出由图节点和边组成,这些节点和边已准备好被摄取到图数据库中。
def _convert_extractions_to_graph(self, extractions: list):
"""Convert langextract's flat, grouped extractions into (nodes, relationships)."""
groups: dict[str, list] = {}
for ext in extractions:
if not ext.attributes or "medication_group" not in ext.attributes:
continue
group_name = ext.attributes["medication_group"]
groups.setdefault(group_name, []).append(ext)
nodes: dict[str, str] = {}
relationships: list[dict] = []
for group_name, group_extractions in groups.items():
anchor_ext = next(
(e for e in group_extractions if e.extraction_class == "medication"),
None,
)
# Fall back to the group name itself if no explicit "medication"
# extraction was found in this group, so we still get an anchor.
anchor_text = anchor_ext.extraction_text if anchor_ext else group_name
if anchor_text not in nodes:
nodes[anchor_text] = str(uuid.uuid4())
for ext in group_extractions:
if ext is anchor_ext:
continue
target_text = ext.extraction_text
if target_text not in nodes:
nodes[target_text] = str(uuid.uuid4())
relationships.append(
{
"source": nodes[anchor_text],
"target": nodes[target_text],
"type": ext.extraction_class,
}
)
return nodes, relationshipsingest_to_neo4j()ingest_to_neo4j()
This method persists the generated graph structure into Neo4j. Each extracted entity is stored as a graph node, while semantic relationships are stored as graph edges. By storing data in this format, Neo4j can later perform efficient graph traversals and relationship exploration. The method ensures that every node maintains a unique identifier, allowing it to be linked with vector search results. Once completed, the graph becomes the system’s structured knowledge repository.此方法将生成的图结构持久化到 Neo4j 中。每个提取的实体都存储为图节点,而语义关系则存储为图边。通过以这种格式存储数据,Neo4j 以后可以执行高效的图遍历和关系探索。该方法确保每个节点都维护一个唯一标识符,允许将其与向量搜索结果关联起来。完成后,图谱将成为系统的结构化知识库。
def ingest_to_neo4j(self, nodes: dict, relationships: list):
"""
Ingest nodes and relationships into Neo4j.
"""
with self.neo4j_driver.session() as session:
# Create nodes in Neo4j
for name, node_id in nodes.items():
session.run(
"CREATE (n:Entity {id: $id, name: $name})",
id=node_id,
name=name,
)
# Create relationships in Neo4j, using the semantic type
# (dosage/frequency/condition/etc.) as the actual relationship
# label instead of a generic "RELATIONSHIP" type.
for relationship in relationships:
rel_type = self._sanitize_relationship_type(relationship["type"])
session.run(
"MATCH (a:Entity {id: $source_id}), (b:Entity {id: $target_id}) "
f"CREATE (a)-[:{rel_type} {{type: $type}}]->(b)",
source_id=relationship["source"],
target_id=relationship["target"],
type=relationship["type"],
)
return nodes_sanitize_relationship_type()_sanitize_relationship_type()
Since relationship names originate from LLM-generated extractions, they may contain invalid characters or formats. This method cleans and standardizes relationship labels before they are inserted into Neo4j. The transformation converts labels into safe uppercase identifiers that comply with Cypher requirements. It also protects the system from malformed relationship names and potential query issues. Although small, this method plays an important role in maintaining graph integrity.由于关系名称源自 LLM 生成的提取,因此它们可能包含无效字符或格式。此方法在将关系标签插入 Neo4j 之前对其进行清理和标准化。转换将标签转换为符合 Cypher 要求的安全大写标识符。它还可以保护系统免受格式错误的名称和潜在的查询问题的影响。尽管此方法很小,但它在维护图谱完整性方面起着重要作用。
@staticmethod
def _sanitize_relationship_type(raw_type: str) -> str:
"""
Cypher relationship types can't be passed as query parameters, so
they have to be interpolated into the query string directly. Since
raw_type comes from LLM-extracted text, sanitize it to a safe
UPPER_SNAKE_CASE identifier before interpolation, to avoid Cypher
injection or syntax errors from unexpected characters.
"""
safe = "".join(ch if ch.isalnum() else "_" for ch in raw_type.strip())
safe = safe.upper().strip("_") or "RELATIONSHIP"
if safe[0].isdigit():
safe = f"REL_{safe}"
return safecreate_collection()create_collection()
Before vectors can be stored, a collection must exist in Qdrant. This method checks whether the specified collection is already available and creates it if necessary. It also configures vector dimensions and similarity metrics that will be used during retrieval. By performing this validation step, the system avoids unnecessary collection recreation. The method ensures that the vector storage layer is properly prepared before ingestion begins.在存储向量之前,必须存在一个 Qdrant 集合。此方法检查指定的集合是否已可用,并在必要时创建它。它还配置将在检索期间使用的向量维度和相似性度量。通过执行此验证步骤,系统可以避免不必要的集合重新创建。该方法确保在摄取开始之前向量存储层已正确准备好。
def create_collection(self, collection_name: str, vector_dimension: int = None):
vector_dimension = vector_dimension or self.vector_dimension
try:
# Try to fetch the collection status
self.qdrant_client.get_collection(collection_name)
print(f"Skipping creating collection; '{collection_name}' already exists.")
except Exception as e:
# If collection does not exist, an error will be thrown, so we create the collection
if "Not found: Collection" in str(e) or "doesn't exist" in str(e) or "404" in str(e):
print(f"Collection '{collection_name}' not found. Creating it now...")
self.qdrant_client.create_collection(
collection_name=collection_name,
vectors_config=models.VectorParams(
size=vector_dimension, distance=models.Distance.COSINE
),
)
print(f"Collection '{collection_name}' created successfully.")
else:
print(f"Error while checking collection: {e}")ollama_embeddings()ollama_embeddings()
This method generates dense vector representations using Ollama’s embedding model. Every graph entity and user query eventually passes through this function. The generated embeddings capture semantic meaning in a numerical form that can be compared efficiently. These vectors enable similarity search within Qdrant. In many ways, this method acts as the bridge between natural language and vector retrieval.此方法使用 Ollama 的嵌入模型生成密集向量表示。每个图实体和用户查询最终都通过此函数。生成的嵌入以数值形式捕获语义含义,可以对其进行有效比较。这些向量支持 Qdrant 中的相似性搜索。在许多方面,此方法充当自然语言和向量检索之间的桥梁。
def ollama_embeddings(self, text: str) -> list[float]:
response = self.ollama_client.embeddings(
model=self.ollama_embedding_model,
prompt=text,
)
return response["embedding"]ingest_to_qdrant()ingest_to_qdrant()
After graph nodes are created, this method generates embeddings for each entity and stores them in Qdrant. Along with the embedding, it stores metadata such as the Neo4j node identifier and entity name. This mapping creates a direct connection between the vector database and graph database. During retrieval, vector search results can therefore be translated back into graph entities. The method effectively builds the semantic search layer of the architecture.创建图节点后,此方法为每个实体生成嵌入并将其存储在 Qdrant 中。除了嵌入之外,它还存储元数据,例如 Neo4j 节点标识符和实体名称。此映射在向量数据库和图数据库之间创建了直接连接。因此,在检索期间,向量搜索结果可以转换回图实体。该方法有效地构建了架构的语义搜索层。
def ingest_to_qdrant(self, collection_name: str, raw_data: str, node_id_mapping: dict):
names = list(node_id_mapping.keys())
embeddings = [self.ollama_embeddings(name) for name in names]
self.qdrant_client.upsert(
collection_name=collection_name,
points=[
{
"id": str(uuid.uuid4()),
"vector": embedding,
"payload": {"id": node_id_mapping[name], "name": name},
}
for name, embedding in zip(names, embeddings)
],
)retriever_search()retriever_search()
This method performs semantic retrieval during query execution. The user query is first converted into an embedding and then compared against vectors stored in Qdrant. Rather than retrieving text chunks, the search returns graph entities that are semantically similar to the query. These entities serve as entry points into the knowledge graph. The result is a retrieval process that is concept-driven rather than document-driven.此方法在查询执行期间执行语义检索。用户查询首先转换为嵌入,然后与存储在 Qdrant 中的向量进行比较。搜索返回与查询语义相似的图实体,而不是检索文本块。这些实体充当知识图谱的入口点。结果是一个由概念驱动而不是文档驱动的检索过程。
def retriever_search(self, collection_name: str, query: str, top_k: int = 5):
retriever = QdrantNeo4jRetriever(
driver=self.neo4j_driver,
client=self.qdrant_client,
collection_name=collection_name,
id_property_external="id",
id_property_neo4j="id",
)
results = retriever.search(
query_vector=self.ollama_embeddings(query), top_k=top_k
)
return resultsfetch_related_graph()fetch_related_graph()
Once relevant entities are identified, this method queries Neo4j to retrieve their surrounding context. It performs graph traversal to collect neighboring nodes and relationships connected to the retrieved entities. This expansion process enriches the retrieved information with additional context that may not have been directly matched during vector search. As a result, the system gains access to a meaningful subgraph instead of isolated entities. This step is what gives GraphRAG its relational reasoning capabilities.一旦识别出相关实体,此方法就会查询 Neo4j 以检索其周围的上下文。它执行图谱遍历以收集与检索到的实体连接的相邻节点和关系。此扩展过程通过其他上下文丰富检索到的信息,这些上下文可能在向量搜索期间未被直接匹配。因此,系统可以访问有意义的子图谱而不是孤立的实体。此步骤赋予了 GraphRAG 关系推理能力。
def fetch_related_graph(self, entity_ids: list):
query = """
MATCH (e:Entity)-[r1]-(n1)-[r2]-(n2)
WHERE e.id IN $entity_ids
RETURN e, r1 as r, n1 as related, r2, n2
UNION
MATCH (e:Entity)-[r]-(related)
WHERE e.id IN $entity_ids
RETURN e, r, related, null as r2, null as n2
"""
with self.neo4j_driver.session() as session:
result = session.run(query, entity_ids=entity_ids)
subgraph = []
for record in result:
subgraph.append(
{
"entity": record["e"],
"relationship": record["r"],
"related_node": record["related"],
}
)
if record["r2"] and record["n2"]:
subgraph.append(
{
"entity": record["related"],
"relationship": record["r2"],
"related_node": record["n2"],
}
)
return subgraphformat_graph_context()format_graph_context()
The retrieved subgraph is not immediately suitable for LLM consumption. This method converts graph structures into a clean textual representation consisting of nodes and relationship statements. Relationships are transformed into readable triples that explicitly describe how entities are connected. The resulting format retains the structure of the graph while making it understandable for a language model. This serves as the final context preparation stage before answer generation.检索到的子图谱并不适合立即用于 LLM。此方法将图结构转换为干净的文本表示,由节点和关系语句组成。关系被转换为可读的三元组,以显式描述实体如何连接。生成的格式保留了图谱的结构,同时使其对语言模型可理解。这是答案生成之前的最终上下文准备阶段。
def format_graph_context(self, subgraph: list):
nodes = set()
edges = []
for entry in subgraph:
entity = entry["entity"]
related = entry["related_node"]
relationship = entry["relationship"]
nodes.add(entity["name"])
nodes.add(related["name"])
edges.append(f"{entity['name']} {relationship['type']} {related['name']}")
return {"nodes": list(nodes), "edges": edges}graphRAG_run()graphRAG_run()
This method is responsible for generating the final answer. It combines the formatted graph context with the user’s question and constructs a prompt for the language model. The LLM receives graph-grounded information instead of raw document chunks, allowing it to reason over relationships and connected facts. Once the model processes the prompt, it generates a response based on the retrieved graph knowledge. This is the final reasoning layer of the GraphRAG pipeline.此方法负责生成最终答案。它将格式化的图谱上下文与用户的问题结合起来,并为语言模型构建提示。LLM 接收基于图谱的信息,而不是原始文档块,这使其能够推理关系和连接的事实。模型处理完提示后,它会根据检索到的图谱知识生成响应。这是 GraphRAG 管道的最终推理层。
def graphRAG_run(self, graph_context: dict, user_query: str):
nodes_str = ", ".join(graph_context["nodes"])
edges_str = "; ".join(graph_context["edges"])
prompt = f"""
You are an intelligent assistant with access to the following knowledge graph:
Nodes: {nodes_str}
Edges: {edges_str}
Using this graph, Answer the following question:
User Query: "{user_query}"
"""
try:
response = chat(
model=self.ollama_model_answer,
messages=[
{
"role": "system",
"content": "Provide the answer for the following question:",
},
{"role": "user", "content": prompt},
],
)
return response.message.content
except Exception as e:
return f"Error querying LLM: {str(e)}"create_and_ingest()create_and_ingest()
This method orchestrates the complete ingestion workflow. It creates the vector collection, extracts graph components, stores them in Neo4j, generates embeddings, and indexes entities in Qdrant. Running this method converts raw text into a fully searchable GraphRAG knowledge base. It is typically executed once during the data preparation phase. After completion, the system becomes ready for querying.此方法协调完整的摄取工作流。它创建向量集合,提取图谱组件,将它们存储在 Neo4j 中,生成嵌入,并将实体索引到 Qdrant 中。运行此方法可将原始文本转换为完全可搜索的 GraphRAG 知识库。它通常在数据准备阶段执行一次。完成后,系统即可进行查询。
def create_and_ingest(self, raw_data: str, query: str, collection_name: str = "medicationGraphRAGstore"):
print("Creating collection...")
self.create_collection(collection_name, self.vector_dimension)
print("Collection created/verified")
print("Extracting graph components...")
nodes, relationships = self.extract_graph_components(raw_data)
print("Nodes:", nodes)
print("Relationships:", relationships)
print("Ingesting to Neo4j...")
node_id_mapping = self.ingest_to_neo4j(nodes, relationships)
print("Neo4j ingestion complete")
print("Ingesting to Qdrant...")
self.ingest_to_qdrant(collection_name, raw_data, node_id_mapping)
print("Qdrant ingestion complete")run_pipeline()run_pipeline()
This method orchestrates the end-to-end retrieval and reasoning workflow. It starts with semantic retrieval from Qdrant, extracts the corresponding graph entities, and performs graph traversal in Neo4j. The retrieved subgraph is then formatted into LLM-friendly context and passed to the reasoning model. Finally, the generated answer is returned to the user. This method represents the complete GraphRAG execution pipeline from question to answer.此方法协调端到端的检索和推理工作流。它从 Qdrant 的语义检索开始,提取相应的图实体,并在 Neo4j 中执行图谱遍历。然后将检索到的子图谱格式化为 LLM 友好的上下文,并传递给推理模型。最后,将生成的答案返回给用户。此方法代表了从问题到答案的完整 GraphRAG 执行管道。
def run_pipeline(self, raw_data: str, query: str, collection_name: str = "medicationGraphRAGstore"):
# run only the first time, comment this for subsequent runs
# self.create_and_ingest(raw_data, query, collection_name)
print("Starting retriever search...")
retriever_result = self.retriever_search(collection_name, query)
print("Retriever results:", retriever_result)
print("Extracting entity IDs...")
entity_ids = [
item.content.split("'id': '")[1].split("'")[0]
for item in retriever_result.items
]
print("Entity IDs:", entity_ids)
print("Fetching related graph...")
subgraph = self.fetch_related_graph(entity_ids)
print("Subgraph:", subgraph)
print("Formatting graph context...")
graph_context = self.format_graph_context(subgraph)
print("Graph context:", graph_context)
print("Running GraphRAG...")
answer = self.graphRAG_run(graph_context, query)
print("Final Answer:", answer)
return answerclose()close()
The final method handles resource cleanup. It safely closes the Neo4j driver connection and releases any associated resources. This helps prevent connection leaks and ensures graceful application shutdown. Although simple, it is an important part of maintaining system stability. It should always be called when processing is complete.最后的方法处理资源清理。它安全地关闭 Neo4j 驱动程序连接并释放任何相关资源。这有助于防止连接泄漏并确保应用程序正常关闭。尽管很简单,但它是维护系统稳定性的重要组成部分。处理完成后应始终调用它。
def close(self):
self.neo4j_driver.close()The Driver Code:驱动代码:
if __name__ == "__main__":
print("Script started")
graph_rag = MedicationGraphRAG(env_path="../.env")
# Example-1
# raw_data = textwrap.dedent("""
# The patient was prescribed Lisinopril and Metformin last month.
# He takes the Lisinopril 10mg daily for hypertension, but often misses
# his Metformin 500mg dose which should be taken twice daily for diabetes.
# """).strip()
# Example-2
raw_data = textwrap.dedent("""
The patient is a 62-year-old man with a history of multiple chronic conditions
being managed through an extensive medication regimen. He was prescribed
Lisinopril, Metformin, Atorvastatin, Aspirin, Levothyroxine, and Sertraline
over the course of the past year, with his treatment plan adjusted several
times based on follow-up visits.
He takes Lisinopril 10mg daily for hypertension, but often misses his
Metformin 500mg dose which should be taken twice daily for diabetes. His
cardiologist also started him on Atorvastatin 40mg at bedtime for high
cholesterol after his last lipid panel showed elevated LDL levels. To reduce
his risk of cardiovascular events, he was additionally prescribed Aspirin
81mg daily for heart disease prevention, which he takes alongside his
breakfast each morning.
Following a routine thyroid screening, he was found to have an underactive
thyroid and was started on Levothyroxine 75mcg every morning for
hypothyroidism, to be taken on an empty stomach before any other medications.
More recently, after reporting persistent low mood and difficulty sleeping
during a wellness visit, his primary care physician added Sertraline 50mg
daily for depression, with plans to reassess the dosage after eight weeks.
Despite the number of prescriptions, the patient has had difficulty
maintaining consistency with his Metformin and occasionally forgets his
evening Atorvastatin dose, which his care team is now addressing through a
simplified pill organizer and reminder system.
""").strip()
# Sample Questions
#1. "What is the dosage and frequency for Lisinopril?"
#2. "What is the dosage and frequency for Metformin?"
#3. "Which medications does the patient take once daily versus twice daily?"
#4. "What medication is prescribed for hypothyroidism, and at what dose?"
#5. "List all medications related to cardiovascular conditions and their dosages."
#6. "How often does the patient take Aspirin?"
#7. "What condition is Levothyroxine prescribed for?"
#8. "What time of day should Levothyroxine be taken, and why?"
#9. "Which medications does the patient have trouble taking consistently?"
#10. "What is the dosage and frequency for Sertraline?"
query = "List all medications related to cardiovascular conditions and their dosages."
answer = graph_rag.run_pipeline(raw_data, query, collection_name="medicationGraphRAGstore")
graph_rag.close()Putting it all together整合
import os
import uuid
import textwrap
import ollama
from dotenv import load_dotenv, find_dotenv
from ollama import chat
from neo4j import GraphDatabase
from qdrant_client import QdrantClient, models
from neo4j_graphrag.retrievers import QdrantNeo4jRetriever
import langextract as lx
from langextract.providers import ollama as lx_ollama
load_dotenv(find_dotenv())
class MedicationGraphRAG:
def __init__(self,env_path: str = ".env",ollama_model_extract: str = "gemma3:latest",
ollama_model_answer: str = "gemma3:latest",ollama_embedding_model: str = "embeddinggemma:latest",
ollama_host: str | None = None,vector_dimension: int = 768,
):
load_dotenv(env_path)
self.qdrant_key = os.getenv("QDRANT_KEY")
self.qdrant_url = os.getenv("QDRANT_URL")
self.neo4j_uri = os.getenv("NEO4J_URI")
self.neo4j_username = os.getenv("NEO4J_USERNAME")
self.neo4j_password = os.getenv("NEO4J_PASSWORD")
self.neo4j_driver = GraphDatabase.driver(
self.neo4j_uri, auth=(self.neo4j_username, self.neo4j_password)
)
self.qdrant_client = QdrantClient(
url=self.qdrant_url,
api_key=self.qdrant_key,
)
# Ollama client for local embeddings (embeddinggemma:latest)
self.ollama_client = ollama.Client(host=ollama_host) if ollama_host else ollama.Client()
# langextract needs a plain URL string, not a client object
self.ollama_url = ollama_host or os.environ.get("OLLAMA_HOST", "http://localhost:11434")
# Model / config knobs
self.ollama_model_extract = ollama_model_extract
self.ollama_model_answer = ollama_model_answer
self.ollama_embedding_model = ollama_embedding_model
self.vector_dimension = vector_dimension
def extract_graph_components(self, raw_data: str):
"""Extract medication entities and relationships using langextract + Ollama."""
prompt_description = textwrap.dedent("""
Extract medications with their details, using attributes to group related information:
1. Extract entities in the order they appear in the text
2. Each entity must have a 'medication_group' attribute linking it to its medication
3. All details about a medication should share the same medication_group value
""").strip()
examples = [
lx.data.ExampleData(
text=(
"Patient takes Aspirin 100mg daily for heart health and"
" Simvastatin 20mg at bedtime."
),
extractions=[
lx.data.Extraction(
extraction_class="medication",
extraction_text="Aspirin",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="dosage",
extraction_text="100mg",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="frequency",
extraction_text="daily",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="condition",
extraction_text="heart health",
attributes={"medication_group": "Aspirin"},
),
lx.data.Extraction(
extraction_class="medication",
extraction_text="Simvastatin",
attributes={"medication_group": "Simvastatin"},
),
lx.data.Extraction(
extraction_class="dosage",
extraction_text="20mg",
attributes={"medication_group": "Simvastatin"},
),
lx.data.Extraction(
extraction_class="frequency",
extraction_text="at bedtime",
attributes={"medication_group": "Simvastatin"},
),
],
)
]
result = lx.extract(
text_or_documents=raw_data,
prompt_description=prompt_description,
examples=examples,
model_id=self.ollama_model_extract,
model_url=self.ollama_url,
resolver_params={"format_handler": lx_ollama.OLLAMA_FORMAT_HANDLER},
max_char_buffer=4000,
show_progress=True,
)
return self._convert_extractions_to_graph(result.extractions)
def _convert_extractions_to_graph(self, extractions: list):
"""Convert langextract's flat, grouped extractions into (nodes, relationships)."""
groups: dict[str, list] = {}
for ext in extractions:
if not ext.attributes or "medication_group" not in ext.attributes:
continue
group_name = ext.attributes["medication_group"]
groups.setdefault(group_name, []).append(ext)
nodes: dict[str, str] = {}
relationships: list[dict] = []
for group_name, group_extractions in groups.items():
anchor_ext = next(
(e for e in group_extractions if e.extraction_class == "medication"),
None,
)
# Fall back to the group name itself if no explicit "medication"
# extraction was found in this group, so we still get an anchor.
anchor_text = anchor_ext.extraction_text if anchor_ext else group_name
if anchor_text not in nodes:
nodes[anchor_text] = str(uuid.uuid4())
for ext in group_extractions:
if ext is anchor_ext:
continue
target_text = ext.extraction_text
if target_text not in nodes:
nodes[target_text] = str(uuid.uuid4())
relationships.append(
{
"source": nodes[anchor_text],
"target": nodes[target_text],
"type": ext.extraction_class,
}
)
return nodes, relationships
def ingest_to_neo4j(self, nodes: dict, relationships: list):
"""
Ingest nodes and relationships into Neo4j.
"""
with self.neo4j_driver.session() as session:
# Create nodes in Neo4j
for name, node_id in nodes.items():
session.run(
"CREATE (n:Entity {id: $id, name: $name})",
id=node_id,
name=name,
)
# Create relationships in Neo4j, using the semantic type
# (dosage/frequency/condition/etc.) as the actual relationship
# label instead of a generic "RELATIONSHIP" type.
for relationship in relationships:
rel_type = self._sanitize_relationship_type(relationship["type"])
session.run(
"MATCH (a:Entity {id: $source_id}), (b:Entity {id: $target_id}) "
f"CREATE (a)-[:{rel_type} {{type: $type}}]->(b)",
source_id=relationship["source"],
target_id=relationship["target"],
type=relationship["type"],
)
return nodes
@staticmethod
def _sanitize_relationship_type(raw_type: str) -> str:
"""
Cypher relationship types can't be passed as query parameters, so
they have to be interpolated into the query string directly. Since
raw_type comes from LLM-extracted text, sanitize it to a safe
UPPER_SNAKE_CASE identifier before interpolation, to avoid Cypher
injection or syntax errors from unexpected characters.
"""
safe = "".join(ch if ch.isalnum() else "_" for ch in raw_type.strip())
safe = safe.upper().strip("_") or "RELATIONSHIP"
if safe[0].isdigit():
safe = f"REL_{safe}"
return safe
def create_collection(self, collection_name: str, vector_dimension: int = None):
vector_dimension = vector_dimension or self.vector_dimension
try:
# Try to fetch the collection status
self.qdrant_client.get_collection(collection_name)
print(f"Skipping creating collection; '{collection_name}' already exists.")
except Exception as e:
# If collection does not exist, an error will be thrown, so we create the collection
if "Not found: Collection" in str(e) or "doesn't exist" in str(e) or "404" in str(e):
print(f"Collection '{collection_name}' not found. Creating it now...")
self.qdrant_client.create_collection(
collection_name=collection_name,
vectors_config=models.VectorParams(
size=vector_dimension, distance=models.Distance.COSINE
),
)
print(f"Collection '{collection_name}' created successfully.")
else:
print(f"Error while checking collection: {e}")
def ollama_embeddings(self, text: str) -> list[float]:
response = self.ollama_client.embeddings(
model=self.ollama_embedding_model,
prompt=text,
)
return response["embedding"]
def ingest_to_qdrant(self, collection_name: str, raw_data: str, node_id_mapping: dict):
names = list(node_id_mapping.keys())
embeddings = [self.ollama_embeddings(name) for name in names]
self.qdrant_client.upsert(
collection_name=collection_name,
points=[
{
"id": str(uuid.uuid4()),
"vector": embedding,
"payload": {"id": node_id_mapping[name], "name": name},
}
for name, embedding in zip(names, embeddings)
],
)
def retriever_search(self, collection_name: str, query: str, top_k: int = 5):
retriever = QdrantNeo4jRetriever(
driver=self.neo4j_driver,
client=self.qdrant_client,
collection_name=collection_name,
id_property_external="id",
id_property_neo4j="id",
)
results = retriever.search(
query_vector=self.ollama_embeddings(query), top_k=top_k
)
return results
def fetch_related_graph(self, entity_ids: list):
query = """
MATCH (e:Entity)-[r1]-(n1)-[r2]-(n2)
WHERE e.id IN $entity_ids
RETURN e, r1 as r, n1 as related, r2, n2
UNION
MATCH (e:Entity)-[r]-(related)
WHERE e.id IN $entity_ids
RETURN e, r, related, null as r2, null as n2
"""
with self.neo4j_driver.session() as session:
result = session.run(query, entity_ids=entity_ids)
subgraph = []
for record in result:
subgraph.append(
{
"entity": record["e"],
"relationship": record["r"],
"related_node": record["related"],
}
)
if record["r2"] and record["n2"]:
subgraph.append(
{
"entity": record["related"],
"relationship": record["r2"],
"related_node": record["n2"],
}
)
return subgraph
def format_graph_context(self, subgraph: list):
nodes = set()
edges = []
for entry in subgraph:
entity = entry["entity"]
related = entry["related_node"]
relationship = entry["relationship"]
nodes.add(entity["name"])
nodes.add(related["name"])
edges.append(f"{entity['name']} {relationship['type']} {related['name']}")
return {"nodes": list(nodes), "edges": edges}
def graphRAG_run(self, graph_context: dict, user_query: str):
nodes_str = ", ".join(graph_context["nodes"])
edges_str = "; ".join(graph_context["edges"])
prompt = f"""
You are an intelligent assistant with access to the following knowledge graph:
Nodes: {nodes_str}
Edges: {edges_str}
Using this graph, Answer the following question:
User Query: "{user_query}"
"""
try:
response = chat(
model=self.ollama_model_answer,
messages=[
{
"role": "system",
"content": "Provide the answer for the following question:",
},
{"role": "user", "content": prompt},
],
)
return response.message.content
except Exception as e:
return f"Error querying LLM: {str(e)}"
def create_and_ingest(self, raw_data: str, query: str, collection_name: str = "medicationGraphRAGstore"):
print("Creating collection...")
self.create_collection(collection_name, self.vector_dimension)
print("Collection created/verified")
print("Extracting graph components...")
nodes, relationships = self.extract_graph_components(raw_data)
print("Nodes:", nodes)
print("Relationships:", relationships)
print("Ingesting to Neo4j...")
node_id_mapping = self.ingest_to_neo4j(nodes, relationships)
print("Neo4j ingestion complete")
print("Ingesting to Qdrant...")
self.ingest_to_qdrant(collection_name, raw_data, node_id_mapping)
print("Qdrant ingestion complete")
def run_pipeline(self, raw_data: str, query: str, collection_name: str = "medicationGraphRAGstore"):
# run only the first time, comment this for subsequent runs
# self.create_and_ingest(raw_data, query, collection_name)
print("Starting retriever search...")
retriever_result = self.retriever_search(collection_name, query)
print("Retriever results:", retriever_result)
print("Extracting entity IDs...")
entity_ids = [
item.content.split("'id': '")[1].split("'")[0]
for item in retriever_result.items
]
print("Entity IDs:", entity_ids)
print("Fetching related graph...")
subgraph = self.fetch_related_graph(entity_ids)
print("Subgraph:", subgraph)
print("Formatting graph context...")
graph_context = self.format_graph_context(subgraph)
print("Graph context:", graph_context)
print("Running GraphRAG...")
answer = self.graphRAG_run(graph_context, query)
print("Final Answer:", answer)
return answer
def close(self):
self.neo4j_driver.close()
if __name__ == "__main__":
print("Script started")
graph_rag = MedicationGraphRAG(env_path="../.env")
# Example-1
# raw_data = textwrap.dedent("""
# The patient was prescribed Lisinopril and Metformin last month.
# He takes the Lisinopril 10mg daily for hypertension, but often misses
# his Metformin 500mg dose which should be taken twice daily for diabetes.
# """).strip()
# Example-2
raw_data = textwrap.dedent("""
The patient is a 62-year-old man with a history of multiple chronic conditions
being managed through an extensive medication regimen. He was prescribed
Lisinopril, Metformin, Atorvastatin, Aspirin, Levothyroxine, and Sertraline
over the course of the past year, with his treatment plan adjusted several
times based on follow-up visits.
He takes Lisinopril 10mg daily for hypertension, but often misses his
Metformin 500mg dose which should be taken twice daily for diabetes. His
cardiologist also started him on Atorvastatin 40mg at bedtime for high
cholesterol after his last lipid panel showed elevated LDL levels. To reduce
his risk of cardiovascular events, he was additionally prescribed Aspirin
81mg daily for heart disease prevention, which he takes alongside his
breakfast each morning.
Following a routine thyroid screening, he was found to have an underactive
thyroid and was started on Levothyroxine 75mcg every morning for
hypothyroidism, to be taken on an empty stomach before any other medications.
More recently, after reporting persistent low mood and difficulty sleeping
during a wellness visit, his primary care physician added Sertraline 50mg
daily for depression, with plans to reassess the dosage after eight weeks.
Despite the number of prescriptions, the patient has had difficulty
maintaining consistency with his Metformin and occasionally forgets his
evening Atorvastatin dose, which his care team is now addressing through a
simplified pill organizer and reminder system.
""").strip()
# Sample Questions
#1. "What is the dosage and frequency for Lisinopril?"
#2. "What is the dosage and frequency for Metformin?"
#3. "Which medications does the patient take once daily versus twice daily?"
#4. "What medication is prescribed for hypothyroidism, and at what dose?"
#5. "List all medications related to cardiovascular conditions and their dosages."
#6. "How often does the patient take Aspirin?"
#7. "What condition is Levothyroxine prescribed for?"
#8. "What time of day should Levothyroxine be taken, and why?"
#9. "Which medications does the patient have trouble taking consistently?"
#10. "What is the dosage and frequency for Sertraline?"
query = "List all medications related to cardiovascular conditions and their dosages."
answer = graph_rag.run_pipeline(raw_data, query, collection_name="medicationGraphRAGstore")
graph_rag.close()The Run:运行:


query = "List all medications related to cardiovascular conditions and their dosages."
Console:
Starting retriever search...
Retriever results: items=[RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}> score=0.5062605>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}> score=0.47961158>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}> score=0.45777896>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}> score=0.45199984>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}> score=0.4511963>", metadata=None)] metadata={'__retriever': 'QdrantNeo4jRetriever'}
Extracting entity IDs...
Entity IDs: ['1c9fb28e-c3e1-4515-afa0-01939beac419', '1db81626-c3de-4cab-b5dd-091327785182', '44573186-869f-4d5d-ba04-fe254ec4ed21', '04f27c55-38a3-46a9-a411-4faf07836a56', '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb']
Fetching related graph...
Subgraph: [{'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:5' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:4' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:5' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:3' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:5' labels=frozenset({'Entity'}) properties={'name': '81mg', 'id': '9d1d3859-cf6f-4a22-81b8-7d80e3cc8e89'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:5' labels=frozenset({'Entity'}) properties={'name': '81mg', 'id': '9d1d3859-cf6f-4a22-81b8-7d80e3cc8e89'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:17' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:4' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:2' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:3' labels=frozenset({'Entity'}) properties={'name': 'high cholesterol', 'id': 'dc85b413-3eca-4f26-a1dd-95de9d61e46c'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:3' labels=frozenset({'Entity'}) properties={'name': 'high cholesterol', 'id': 'dc85b413-3eca-4f26-a1dd-95de9d61e46c'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:1' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:2' labels=frozenset({'Entity'}) properties={'name': 'at bedtime', 'id': 'f9a049d4-bdb9-443d-a70f-3aa0ad290f5d'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:2' labels=frozenset({'Entity'}) properties={'name': 'at bedtime', 'id': 'f9a049d4-bdb9-443d-a70f-3aa0ad290f5d'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:0' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:0' labels=frozenset({'Entity'}) properties={'name': 'Atorvastatin', 'id': '1db81626-c3de-4cab-b5dd-091327785182'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:1' labels=frozenset({'Entity'}) properties={'name': '40mg', 'id': '960fd15d-ad36-4b90-aede-3473dd53f70c'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:1' labels=frozenset({'Entity'}) properties={'name': '40mg', 'id': '960fd15d-ad36-4b90-aede-3473dd53f70c'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:5' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:8' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:6' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}]
Formatting graph context...
Graph context: {'nodes': ['on an empty stomach before any other medications', 'hypertension', 'Atorvastatin', 'Lisinopril', 'Levothyroxine', 'at bedtime', 'high cholesterol', 'Aspirin', '75mcg', '81mg', 'daily', '10mg', 'heart disease prevention', 'every morning', 'Sertraline', 'hypothyroidism', '40mg'], 'edges': ['heart disease prevention condition Aspirin', 'Aspirin frequency daily', 'heart disease prevention condition Aspirin', 'Aspirin dosage 81mg', 'Lisinopril frequency daily', 'daily frequency Sertraline', 'Lisinopril frequency daily', 'daily frequency Aspirin', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine condition hypothyroidism', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine frequency every morning', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine dosage 75mcg', 'Atorvastatin condition high cholesterol', 'Atorvastatin frequency at bedtime', 'Atorvastatin dosage 40mg', 'heart disease prevention condition Aspirin', 'Levothyroxine route on an empty stomach before any other medications', 'Levothyroxine condition hypothyroidism', 'Levothyroxine frequency every morning', 'Levothyroxine dosage 75mcg', 'Lisinopril condition hypertension', 'Lisinopril frequency daily', 'Lisinopril dosage 10mg', 'on an empty stomach before any other medications route Levothyroxine']}
Running GraphRAG...
Final Answer: Here’s a list of medications related to cardiovascular conditions and their dosages based on the knowledge graph:
* **Aspirin:** 81mg (frequency: daily) - for heart disease prevention.
* **Atorvastatin:** 40mg (frequency: at bedtime) - for high cholesterol.
* **Lisinopril:** 10mg (frequency: daily) - for hypertension.query = "What medication is prescribed for hypothyroidism, and at what dose?"
Console:
Starting retriever search...
Retriever results: items=[RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}> score=0.6616618>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}> score=0.5983002>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}> score=0.4675771>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}> score=0.4620626>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}> score=0.4382253>", metadata=None)] metadata={'__retriever': 'QdrantNeo4jRetriever'}
Extracting entity IDs...
Entity IDs: ['95b91440-5ff1-41eb-a036-b57880094b05', '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb', 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847', '1c9fb28e-c3e1-4515-afa0-01939beac419', 'cddff401-0958-4093-b196-ad270b7aa797']
Fetching related graph...
Subgraph: [{'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:6' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:8' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:6' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:6' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:9' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}]
Formatting graph context...
Graph context: {'nodes': ['Lisinopril', '75mcg', 'twice daily', 'diabetes', 'on an empty stomach before any other medications', 'hypertension', 'daily', 'Metformin', '500mg', '10mg', 'hypothyroidism', 'Levothyroxine', 'every morning'], 'edges': ['10mg dosage Lisinopril', 'Lisinopril condition hypertension', '10mg dosage Lisinopril', 'Lisinopril frequency daily', 'hypothyroidism condition Levothyroxine', 'Levothyroxine route on an empty stomach before any other medications', 'hypothyroidism condition Levothyroxine', 'Levothyroxine frequency every morning', 'hypothyroidism condition Levothyroxine', 'Levothyroxine dosage 75mcg', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine condition hypothyroidism', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine frequency every morning', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine dosage 75mcg', 'Levothyroxine route on an empty stomach before any other medications', 'Levothyroxine condition hypothyroidism', 'Levothyroxine frequency every morning', 'Levothyroxine dosage 75mcg', '10mg dosage Lisinopril', 'Metformin condition diabetes', 'Metformin frequency twice daily', 'Metformin dosage 500mg', 'hypothyroidism condition Levothyroxine', 'on an empty stomach before any other medications route Levothyroxine']}
Running GraphRAG...
Final Answer: Levothyroxine 75mcg is prescribed for hypothyroidism, taken every morning.query = "Which medications does the patient take once daily versus twice daily?"
Console:
Starting retriever search...
Retriever results: items=[RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}> score=0.6052238>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}> score=0.50138044>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}> score=0.424541>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}> score=0.42364278>", metadata=None), RetrieverResultItem(content="<Record node=<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}> score=0.4210245>", metadata=None)] metadata={'__retriever': 'QdrantNeo4jRetriever'}
Extracting entity IDs...
Entity IDs: ['73d5a502-05be-4bb7-916a-10b8ff5130fa', '1c9fb28e-c3e1-4515-afa0-01939beac419', '06da6faa-baa5-4657-a961-5091f58e3058', '9cbb512f-ca6b-47de-bb12-378ac35826bd', 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847']
Fetching related graph...
Subgraph: [{'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:17' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:18' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:22' labels=frozenset({'Entity'}) properties={'name': 'depression', 'id': '3aca7091-a4fa-4b12-ba5a-a8dbbbac5df4'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:22' labels=frozenset({'Entity'}) properties={'name': 'depression', 'id': '3aca7091-a4fa-4b12-ba5a-a8dbbbac5df4'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:17' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:16' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:21' labels=frozenset({'Entity'}) properties={'name': '50mg', 'id': '5fe00dee-bd0f-4476-b5a6-b19974033f78'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:21' labels=frozenset({'Entity'}) properties={'name': '50mg', 'id': '5fe00dee-bd0f-4476-b5a6-b19974033f78'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:4' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:5' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:6' labels=frozenset({'Entity'}) properties={'name': 'heart disease prevention', 'id': '44573186-869f-4d5d-ba04-fe254ec4ed21'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:4' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:3' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:5' labels=frozenset({'Entity'}) properties={'name': '81mg', 'id': '9d1d3859-cf6f-4a22-81b8-7d80e3cc8e89'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:5' labels=frozenset({'Entity'}) properties={'name': '81mg', 'id': '9d1d3859-cf6f-4a22-81b8-7d80e3cc8e89'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:8' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:11' labels=frozenset({'Entity'}) properties={'name': 'hypertension', 'id': '1bc0479e-5e00-4ede-8a9d-704e56f58814'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:6' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:9' labels=frozenset({'Entity'}) properties={'name': '10mg', 'id': 'cddff401-0958-4093-b196-ad270b7aa797'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:9' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:9' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:14' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:18' labels=frozenset({'Entity'}) properties={'name': 'hypothyroidism', 'id': '95b91440-5ff1-41eb-a036-b57880094b05'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:13' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:17' labels=frozenset({'Entity'}) properties={'name': 'every morning', 'id': '7fb1c7e5-e414-43ec-8606-474b08dc9173'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:12' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:16' labels=frozenset({'Entity'}) properties={'name': '75mcg', 'id': '75b6f7a1-2f53-419c-9365-5f026dcb1e25'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:17' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:20' labels=frozenset({'Entity'}) properties={'name': 'Sertraline', 'id': '42844c4c-ce96-4bd9-8d37-d8adad5a75fe'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:4' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:4' labels=frozenset({'Entity'}) properties={'name': 'Aspirin', 'id': '10939c85-6fc1-41b4-9b80-abe1662eda11'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:7' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:10' labels=frozenset({'Entity'}) properties={'name': 'daily', 'id': '06da6faa-baa5-4657-a961-5091f58e3058'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:8' labels=frozenset({'Entity'}) properties={'name': 'Lisinopril', 'id': '04f27c55-38a3-46a9-a411-4faf07836a56'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:9' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>) type='DOSAGE' properties={'type': 'dosage'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:13' labels=frozenset({'Entity'}) properties={'name': '500mg', 'id': '6c38fe32-0ca3-4bcc-a072-05e302aaa8e7'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:10' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:14' labels=frozenset({'Entity'}) properties={'name': 'twice daily', 'id': '73d5a502-05be-4bb7-916a-10b8ff5130fa'}>) type='FREQUENCY' properties={'type': 'frequency'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:11' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:15' labels=frozenset({'Entity'}) properties={'name': 'diabetes', 'id': '9cbb512f-ca6b-47de-bb12-378ac35826bd'}>) type='CONDITION' properties={'type': 'condition'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:12' labels=frozenset({'Entity'}) properties={'name': 'Metformin', 'id': 'd14d70ef-3780-4ebe-b803-1ab8bd8ec847'}>}, {'entity': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>, 'relationship': <Relationship element_id='5:a53f7783-1308-4f3d-9a27-45cede6b6376:15' nodes=(<Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>, <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:19' labels=frozenset({'Entity'}) properties={'name': 'on an empty stomach before any other medications', 'id': '1c9fb28e-c3e1-4515-afa0-01939beac419'}>) type='ROUTE' properties={'type': 'route'}>, 'related_node': <Node element_id='4:a53f7783-1308-4f3d-9a27-45cede6b6376:7' labels=frozenset({'Entity'}) properties={'name': 'Levothyroxine', 'id': '60654f2d-2ec8-4f4e-be02-cd57b7c5abfb'}>}]
Formatting graph context...
Graph context: {'nodes': ['twice daily', 'daily', '75mcg', '50mg', '81mg', 'Aspirin', 'on an empty stomach before any other medications', 'hypothyroidism', 'hypertension', 'depression', 'Lisinopril', 'Levothyroxine', 'heart disease prevention', 'every morning', 'Sertraline', 'diabetes', '500mg', '10mg', 'Metformin'], 'edges': ['daily frequency Sertraline', 'Sertraline condition depression', 'daily frequency Sertraline', 'Sertraline dosage 50mg', 'daily frequency Aspirin', 'Aspirin condition heart disease prevention', 'daily frequency Aspirin', 'Aspirin dosage 81mg', 'daily frequency Lisinopril', 'Lisinopril condition hypertension', 'daily frequency Lisinopril', 'Lisinopril dosage 10mg', 'twice daily frequency Metformin', 'Metformin condition diabetes', 'twice daily frequency Metformin', 'Metformin dosage 500mg', 'diabetes condition Metformin', 'Metformin frequency twice daily', 'diabetes condition Metformin', 'Metformin dosage 500mg', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine condition hypothyroidism', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine frequency every morning', 'on an empty stomach before any other medications route Levothyroxine', 'Levothyroxine dosage 75mcg', 'daily frequency Sertraline', 'daily frequency Aspirin', 'daily frequency Lisinopril', 'Metformin condition diabetes', 'Metformin frequency twice daily', 'Metformin dosage 500mg', 'twice daily frequency Metformin', 'diabetes condition Metformin', 'on an empty stomach before any other medications route Levothyroxine']}
Running GraphRAG...
Final Answer: Here’s the breakdown of medications taken once daily versus twice daily based on the knowledge graph:
**Once Daily:**
* Aspirin: daily frequency
* Sertraline: daily frequency
* Levothyroxine: every morning frequency
**Twice Daily:**
* Metformin: twice daily frequency The Conclusion:结论:
In this article, we learned how to build a complete GraphRAG pipeline using 100% local components powered by Ollama, Neo4j, Qdrant, and LangExtract. We explored how unstructured text can be transformed into structured knowledge through entity and relationship extraction, and how that knowledge can be represented as a graph inside Neo4j. We also saw how Qdrant enables semantic retrieval over graph entities, creating a bridge between vector search and graph traversal. By combining these technologies, we moved beyond traditional chunk-based retrieval and enabled context-aware retrieval driven by connected knowledge. The resulting architecture allows an LLM to reason over relationships rather than isolated pieces of text, leading to more grounded and explainable responses. Most importantly, the entire solution runs locally, giving developers complete control over their data, models, and infrastructure. As GraphRAG continues to gain adoption, architectures like this provide a practical blueprint for building intelligent, relationship-aware retrieval systems using open-source technologies.在本文中,我们学习了如何使用 Ollama、Neo4j、Qdrant 和 LangExtract 提供支持的 100% 本地组件构建完整的 GraphRAG 管道。我们探讨了如何通过实体和关系提取将非结构化文本转换为结构化知识,以及如何将该知识表示为 Neo4j 中的图谱。我们还看到了 Qdrant 如何实现图实体上的语义检索,从而在向量搜索和图谱遍历之间建立桥梁。通过结合这些技术,我们超越了传统的基于块的检索,实现了由连接知识驱动的上下文感知检索。由此产生的架构允许 LLM 推理关系而不是孤立的文本片段,从而获得更具依据和可解释性的响应。最重要的是,整个解决方案都在本地运行,让开发人员能够完全控制他们的数据、模型和基础设施。随着 GraphRAG 的不断普及,像这样的架构为使用开源技术构建智能、关系感知的检索系统提供了实用的蓝图。

