Strona główna / Artykuły / Uwagi praktyczne: Praktyczna architektura GraphRAG wykorzystująca LangExtract i Neo4j

Uwagi praktyczne: Praktyczna architektura GraphRAG wykorzystująca LangExtract i Neo4j

Krok po kroku instrukcja obsługi Notatek praktycznych: Praktyczna architektura GraphRAG wykorzystująca LangExtract i Neo4j – umowy, sprawdzenia oraz gotowe elementy kodu dla zespołów wdrażających ten wzorzec.

8882 słów

Niech to służy jako przebudowa idei z „A Practical GraphRAG Architecture Using LangExtract, Neo4j, Qdrant, and Ollama” przeznaczona dla operatorów: wyraźne etapy, uporządkowane sekcje kodu oraz notatki dotyczące przywracania stanu po przeniesieniu obowiązków. Etap Przeglądu działa najlepiej, gdy traktowany jest jako mierzalna powierzchnia do analizy. Zapisz jeden idealny zapis rozmowy, jeden przypadek awarii oraz notatkę dotyczącą cofnięcia zmian, zanim rozszerzysz zakres pracy. Traktuj ten etap jako umowę pomiędzy danymi wejściowymi a zweryfikowanymi wynikami. Nadaj nazwy poszczególnym elementom, zdefiniuj kryteria sukcesu i odrzucaj ciche, częściowe ukończenie zadań.

Głębsze spojrzenie na architekturę

W fazie dogłębnego analizowania architektury należy zdefiniować dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed zmianą kodu. Operatorzy powinni móc ponownie uruchomić ten krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Należy rejestrować czasy wykonywania oraz koszt tokenów lub zapytań obok wyników funkcjonalnych. Wczesna widoczność kosztów zapobiega nieoczekiwanym rachunkom, gdy proces przechodzi z środowiska demonstracyjnego do współdzielonych środowisk. Należy oddzielić budowanie klienta od pętli komunikacyjnej, aby można było zmieniać dostawców bez konieczności przepisywania maszyny stanu rozmowy.

Szczegółowe omówienie implementacji

W fazie przeglądu implementacji należy zdefiniować dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed zmianą kodu. Operatorzy powinni móc ponownie uruchomić dany krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Konfigurację należy przechowywać poza kodem aplikacji. Pliki środowiskowe, magazyny tajnych danych oraz flagi funkcjonalne powinny znajdować się w jednym miejscu, które operatorzy mogą sprawdzić bez konieczności czytania całej struktury. Należy oddzielić budowę klienta od pętli komunikatów, aby można było zmieniać dostawców bez konieczności przepisywania maszyny stanu rozmowy.

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()
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()

Uruchomienie:

Dla etapu The Run należy zdefiniować dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed modyfikacją kodu. Operatorzy powinni móc ponownie uruchomić ten krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Należy udokumentować zarówno prawidłowy przebieg działania, jak i ścieżkę naprawczą. Próby ponownych działań, kontrolne punkty ludzkie oraz obsługa wiadomości błędowych stanowią część produktu, a nie elementy dodawane później. Należy oddzielić budowę klienta od pętli przekazywania wiadomości, aby można było zmieniać dostawców bez konieczności przepisywania maszyny stanów rozmowy.

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

Wniosek:

W fazie Podsumowanie należy zdefiniować dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed modyfikacją kodu. Operatorzy powinni móc ponownie uruchomić dany krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Należy preferować małe, testowalne jednostki zamiast rozbudowanych skryptów. Gdy dany krok zawiedzie, powinien wskazywać na konkretną odpowiedzialność, a nie na skomplikowany łańcuch operacji. Należy oddzielić budowę klienta od pętli przekazywania wiadomości, aby można było wymieniać dostawców bez konieczności przepisywania maszyny stanu rozmowy.

Lista kontrolna operacyjna

Podczas pracy nad fazą Listy kontrolnej operacyjnej najpierw należy spisać umowę: wymagane dane wejściowe, sygnał sukcesu oraz to, co dzieje się w przypadku częściowego niepowodzenia. Taka lista kontrolna zapewnia uczciwość późniejszych zmian w kodzie.

Należy preferować małe, łatwe do przetestowania jednostki zamiast rozbudowanych skryptów. Gdy jakiś krok zawiedzie, błąd powinien wskazywać na konkretną odpowiedzialność, a nie na skomplikowany łańcuch operacji.

Zapisuj identyfikator żądania, identyfikator modelu oraz czas opóźnienia przy każdym wywołaniu. Bez tych informacji przerywane błędy dostawcy wyglądają jak błędy aplikacji.

Rozdziel politykę dzielenia na fragmenty od polityki pobierania danych. Zmiana jednej z nich nie powinna zmuszać do przepisywania drugiej, gdy zmieniają się metryki jakości.

Gdy budżet na to pozwala, dodaj test sprawdzający kluczowy szlak w procesie CI przy użyciu narzędzi testowych, a nie rzeczywistych płatnych API.

Zachowaj konfigurację poza kodem aplikacji. Pliki środowiskowe, skrypty przechowujące dane poufne oraz flagi funkcjonalne powinny znajdować się w jednym miejscu, które operatorzy mogą sprawdzić bez konieczności analizowania całej struktury.

Zanim wdrożysz cały zestaw narzędzi, zamroź wersje, utwórz dokładny zapis dla kluczowych etapów i potwierdź kroki odwracania zmian. Środowiska współdzielone wymagają ograniczeń szybkości, weryfikacji przynależności oraz wyraźnego właściciela odpowiedzialnego za rotację haseł. Wolimy nudną niezawodność od pomysłowych, jednorazowych demonstracji.

Uwaga dotycząca procesu 0e4c86908c41: unikaj przechowywania kluczy dostawcy w repozytorium, ustaw ograniczenie liczby tokenów na sesję oraz przechowuj zapisy obok plików testowych, aby późniejsze zmiany modeli były porównywalne.

Dla notatki dotyczącej wzmocnienia bezpieczeństwa na etapie 0 zdefiniuj dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed zmianą kodu. Operatorzy powinni móc ponownie uruchomić dany krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Wolimy małe, testowalne jednostki nad rozbudowane skrypty. Gdy jakiś krok zawiedzie, powinien wskazywać na konkretną przyczynę, a nie na skomplikowany łańcuch operacji.

Szczegół wzmocnienia 0/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

Podczas przechodzenia przez pierwszy etap notatki dotyczącej wzmocnienia, najpierw zapisz umowę: wymagane dane wejściowe, sygnał sukcesu oraz to, co dzieje się w przypadku częściowego niepowodzenia. Taka lista kontrolna zapewnia uczciwość późniejszych zmian w kodzie. Zapisz czasy wykonywania oraz koszt tokenów lub zapytań obok wyników funkcjonalnych. Jasna widoczność kosztów zapobiega niespodziewanym rachunkom, gdy ścieżka przechodzi z środowiska demonstracyjnego do współdzielonych środowisk.

Szczegół wzmocnienia 1/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

Druga faza notatki dotyczącej wzmocnienia bezpieczeństwa działa najlepiej, gdy traktuje się ją jako mierzalną powierzchnię do analizy. Zapisz jeden idealny przypadek działania, jeden przypadek awarii oraz notatkę dotyczącą cofnięcia zmian przed rozszerzeniem zakresu prac. Dokumentuj zarówno prawidłowy przebieg działania, jak i ścieżkę przywracania do stanu poprzedniego. Próby ponownych działań, kontrolne punkty ludzkie oraz obsługa wiadomości błędowych stanowią część produktu, a nie elementy dodawane później.

Szczegół 2/771 dotyczący wzmocnienia bezpieczeństwa: zmierz czas wykonywania operacji, klasę błędu oraz zużycie zasobów dla tej notatki, a następnie zdecyduj, czy zachować zmianę, opierając się na ustalonej serii pytań, a nie na indywidualnych obserwacjach.

W przypadku trzeciej fazy notatki dotyczącej wzmocnienia bezpieczeństwa zdefiniuj dane wejściowe, osobę odpowiedzialną za daną czynność oraz kryteria zakończenia przed wprowadzaniem zmian w kodzie. Operatorzy powinni móc ponownie wykonać daną czynność na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu systemu. Traktuj tę fazę jako umowę pomiędzy danymi wejściowymi a zweryfikowanymi wynikami. Nadaj nazwy poszczególnym elementom, zdefiniuj kryteria sukcesu i odrzuć przypadki częściowego ukończenia pracy bez żadnego komunikatu.

Szczegół wzmocnienia 3/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

Podczas przechodzenia przez 4. etap notatki dotyczącej wzmocnienia, najpierw zapisz umowę: wymagane dane wejściowe, sygnał sukcesu oraz to, co dzieje się w przypadku częściowego niepowodzenia. Taka lista kontrolna zapewnia uczciwość późniejszych zmian w kodzie. Trzymaj konfigurację poza kodem aplikacji. Pliki środowiskowe, magazyny tajnych danych oraz flagi funkcjonalne powinny znajdować się w jednym miejscu, które operatorzy mogą sprawdzić bez konieczności czytania całej struktury.

Szczegół wzmocnienia 4/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

Metoda zapisu nr 5 w ramach procesu wzmacniania bezpieczeństwa działa najlepiej, gdy traktuje się ją jako mierzalną powierzchnię do analizy. Zapisz jeden idealny przykład działania, jeden przypadek awarii oraz notatkę dotyczącą cofnięcia zmiany, zanim rozszerzysz zakres prac. Wolno preferować małe, łatwe do przetestowania jednostki nad rozbudowanymi skryptami. Gdy jakaś etapa zawiedzie, awaria powinna wskazywać na konkretną odpowiedzialność, a nie na skomplikowany łańcuch operacji.

Szczegół nr 5/771 dotyczący wzmacniania bezpieczeństwa: zmierz czas wykonywania operacji, klasę błędu oraz ilość zużytych zasobów dla tej notatki, a następnie zdecyduj, czy zachować zmianę, opierając się na ustalonej serii pytań, a nie na indywidualnych obserwacjach.

Dla etapu 6 notatki dotyczącej wzmocnienia bezpieczeństwa należy zdefiniować dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed modyfikacją kodu. Operatorzy powinni móc ponownie wykonać ten krok na podstawie znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Należy rejestrować czasy wykonywania oraz koszt tokenów lub zapytań obok wyników funkcjonalnych. Wczesna widoczność kosztów zapobiega niespodziewanym rachunkom, gdy ścieżka przechodzi z środowiska demonstracyjnego do współdzielonych środowisk.

Szczegóły wzmocnienia bezpieczeństwa 6/771: zmierz czas wykonywania, klasę błędów oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę, opierając się na ustalonej serii pytań, a nie na indywidualnych obserwacjach.

Gdy przechodzisz przez etap nr 7 notatki dotyczącej wzmocnienia bezpieczeństwa, najpierw zapisz umowę: wymagane dane wejściowe, sygnał sukcesu oraz to, co dzieje się w przypadku częściowego awarii. Taka lista kontrolna zapewnia uczciwość późniejszych zmian w kodzie. Zdokumentuj zarówno prawidłowy przebieg działania, jak i ścieżkę odzyskiwania. Próby ponownych działań, kontrolne punkty ludzkie oraz obsługa wiadomości błędowych stanowią część produktu, a nie elementy dodawane później.

Szczegół nr 7/771 dotyczący wzmocnienia bezpieczeństwa: zmierz czas wykonywania operacji, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie informacji anegdotycznych.

Etap nr 8 notatki dotyczącej wzmocnienia bezpieczeństwa działa najlepiej, gdy traktuje się go jako mierzalną powierzchnię do analizy. Zapisz jeden idealny przepływ działania, jeden przypadek awarii oraz notatkę dotyczącą cofnięcia zmian, zanim rozszerzysz zakres prac. Traktuj ten etap jako umowę pomiędzy danymi wejściowymi a zweryfikowanymi wynikami. Nadaj nazwy poszczególnym elementom, zdefiniuj kryteria sukcesu i odrzuć przypadki cichego, częściowego ukończenia zadania.

Szczegóły wzmocnienia bezpieczeństwa 8/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

W etapie 9 notatki dotyczącej wzmocnienia bezpieczeństwa zdefiniuj dane wejściowe, osobę odpowiedzialną za dany krok oraz kryteria zakończenia przed modyfikacją kodu. Operatorzy powinni móc ponownie wykonać ten krok od znanego punktu kontrolnego, bez konieczności zgadywania ukrytego stanu. Konfigurację należy przechowywać poza kodem aplikacji. Pliki środowiskowe, magazyny tajnych danych oraz flagi funkcjonalne powinny znajdować się w jednym miejscu, które operatorzy mogą sprawdzić bez konieczności przeglądania całej struktury.

Szczegóły wzmocnienia bezpieczeństwa 9/771: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie jedynie anegdoty.

Gdy przechodzisz przez etap 10 notatki dotyczącej wzmacniania bezpieczeństwa, najpierw zapisz umowę: wymagane dane wejściowe, sygnał sukcesu oraz to, co dzieje się w przypadku częściowego niepowodzenia. Taka lista kontrolna zapewnia uczciwość późniejszych zmian w kodzie. Wolno preferować małe, testowalne jednostki zamiast rozbudowanych skryptów. Gdy jakiś krok się nie powiedzie, błąd powinien wskazywać na konkretną odpowiedzialność, a nie na skomplikowany proces.

Szczegół 10/771 dotyczący wzmacniania bezpieczeństwa: zmierz czas wykonywania, klasę błędu oraz zużycie tokenów dla tej notatki, a następnie zdecyduj, czy zachować zmianę na podstawie ustalonego zestawu pytań, a nie anegdot.

Literatura pokrewna

  • Praktyczne notatki: Opanowanie Neo4j i LangChain4j: GraphRAG, trwała pamięć AI — Szczegółowy przewodnik po Praktycznych notatkach: Opanowanie Neo4j i LangChain4j: GraphRAG, trwała pamięć AI: umowy, sprawdzenia oraz gotowe fragmenty kodu dla zespołów wdrażających ten wzorzec.