@@ -367,9 +367,14 @@ async def lifespan(app: FastAPI):
367367``` python
368368class Neo4jKnowledgeService :
369369 def __init__ (self ):
370- self .graph_store = None # Neo4j graph store
371- self .knowledge_index = None # LlamaIndex KnowledgeGraphIndex
372- self .query_engine = None # RAG query engine
370+ self .graph_store = None # Neo4j graph store
371+ self .storage_context = None # Shared storage context
372+ self .knowledge_index = None # KnowledgeGraphIndex
373+ self .vector_index = None # VectorStoreIndex for similarity search
374+ self .response_synthesizer = None # LLM-backed synthesizer
375+ self .query_pipeline = None # Graph/Vector pipeline
376+ self .function_tools = [] # Workflow tools
377+ self .tool_node = None # Optional ToolNode
373378 self ._initialized = False
374379```
375380
@@ -389,7 +394,7 @@ sequenceDiagram
389394 KnowServ->>LlamaIndex: Configure Settings
390395 KnowServ->>LlamaIndex: Create KnowledgeGraphIndex
391396 LlamaIndex-->>KnowServ: Index ready
392- KnowServ->>KnowServ: Create query engine
397+ KnowServ->>KnowServ: Build QueryPipeline (graph + vector + synth)
393398 KnowServ-->>Client: Initialized
394399```
395400
@@ -419,24 +424,29 @@ async def add_document(
419424async def query (
420425 self ,
421426 question : str ,
422- top_k : int = 5
427+ * ,
428+ mode : str = " hybrid" ,
429+ use_tools : bool = False
423430) -> Dict[str , Any]:
424- """ Query knowledge base with RAG"""
425- # 1. Use query engine to retrieve relevant context
426- # 2. Generate answer using LLM with context
427- response = await asyncio.to_thread(
428- self .query_engine.query,
429- question
430- )
431+ """ Run the QueryPipeline composed of graph/vector retrievers and a synthesizer."""
432+ config = self ._resolve_pipeline_config(mode, use_tools = use_tools)
433+ result = await asyncio.to_thread(self .query_pipeline.run, question, config)
431434
432- # 3. Return answer with source nodes
433435 return {
434436 " success" : True ,
435- " answer" : str (response),
436- " sources" : [node.metadata for node in response.source_nodes]
437+ " answer" : str (result[" response" ]),
438+ " source_nodes" : format_sources(result[" source_nodes" ]),
439+ " pipeline_steps" : result[" steps" ],
440+ " tool_outputs" : result[" tool_outputs" ]
437441 }
438442```
439443
444+ ** Pipeline Components** :
445+ 1 . ` KnowledgeGraphRAGRetriever ` — extracts entities and traverses the property graph.
446+ 2 . ` VectorIndexRetriever ` — performs vector similarity search over the Neo4j vector index.
447+ 3 . ` ResponseSynthesizer ` — merges retrieved context and generates the final answer.
448+ 4 . ` FunctionTool ` / ` ToolNode ` (optional) — exposes the query as a workflow tool for multi-turn agents.
449+
440450#### 3. Semantic Search
441451``` python
442452async def search_similar (
0 commit comments