node-onj-extraction

This commit is contained in:
Gal Shubeli 2025-03-23 15:25:30 +02:00
parent 3848a1371d
commit 74e5c242c3

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import re import re
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from falkordb.node import Node
from langchain.chains.base import Chain from langchain.chains.base import Chain
from langchain.chains.llm import LLMChain from langchain.chains.llm import LLMChain
@ -164,7 +165,12 @@ class FalkorDBQAChain(Chain):
intermediate_steps.append({"query": generated_cypher}) intermediate_steps.append({"query": generated_cypher})
# Retrieve and limit the number of results # Retrieve and limit the number of results
context = self.graph.query(generated_cypher)[: self.top_k] context_list = self.graph.query(generated_cypher)[: self.top_k]
# If the context is a list of nodes (object), extract the properties
context = [
[r.properties if isinstance(r, Node) else r for r in sublist]
for sublist in context_list
]
if self.return_direct: if self.return_direct:
final_result = context final_result = context