100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
Address Copilot code review feedback
BIBIN PRATHAPa650de13139a
diff --git a/rag_tutorials/knowledge_graph_rag_citations/README.md b/rag_tutorials/knowledge_graph_rag_citations/README.mdindex 551e3741..b1e835de 100644--- a/rag_tutorials/knowledge_graph_rag_citations/README.md+++ b/rag_tutorials/knowledge_graph_rag_citations/README.md@@ -47,7 +47,7 @@ Traditional vector-based RAG finds similar text chunks, but struggles with:```bash# Clone and navigate-cd knowledge_graph_rag_with_citations+cd knowledge_graph_rag_citations# Install dependenciespip install -r requirements.txtdiff --git a/rag_tutorials/knowledge_graph_rag_citations/docker-compose.yml b/rag_tutorials/knowledge_graph_rag_citations/docker-compose.ymlindex 9bcd42d2..7b844af8 100644--- a/rag_tutorials/knowledge_graph_rag_citations/docker-compose.yml+++ b/rag_tutorials/knowledge_graph_rag_citations/docker-compose.yml@@ -9,7 +9,7 @@ services:- "7687:7687" # Boltenvironment:- NEO4J_AUTH=neo4j/password- - NEO4J_PLUGINS=["apoc"]+ - NEO4J_PLUGINS='["apoc"]'volumes:- neo4j_data:/datahealthcheck:diff --git a/rag_tutorials/knowledge_graph_rag_citations/knowledge_graph_rag.py b/rag_tutorials/knowledge_graph_rag_citations/knowledge_graph_rag.pyindex 2b3587dc..64d3e549 100644--- a/rag_tutorials/knowledge_graph_rag_citations/knowledge_graph_rag.py+++ b/rag_tutorials/knowledge_graph_rag_citations/knowledge_graph_rag.py@@ -11,12 +11,19 @@ This example uses Ollama for local LLM inference and Neo4j for the knowledge graimport streamlit as stimport ollama+from ollama import Client as OllamaClientfrom neo4j import GraphDatabase-from typing import List, Dict, Any, Optional+from typing import List, Dict, Tuple+import re+import osfrom dataclasses import dataclassimport jsonimport hashlib+# Configure Ollama host from environment (for Docker)+OLLAMA_HOST = os.environ.get('OLLAMA_HOST', 'http://localhost:11434')+ollama_client = OllamaClient(host=OLLAMA_HOST)+# ============================================================================# Data Models@@ -123,7 +130,7 @@ class KnowledgeGraphManager:result = session.run(f"""MATCH path = (start:Entity)-[*1..{hops}]-(related:Entity)- WHERE start.name CONTAINS $name OR start.description CONTAINS $name+ WHERE toLower(start.name) CONTAINS toLower($name) OR toLower(start.description) CONTAINS toLower($name)RETURN related.name as name,related.description as description,related.source_doc as source,@@ -131,7 +138,7 @@ class KnowledgeGraphManager:[r in relationships(path) | r.description] as path_descriptionsLIMIT 20""",- name=entity_name+ name=entity_name, hops=hops)return [dict(record) for record in result]@@ -160,7 +167,7 @@ class KnowledgeGraphManager:# LLM-based Entity Extraction# ============================================================================-def extract_entities_with_llm(text: str, source_doc: str, model: str = "llama3.2") -> tuple[List[Entity], List[Relationship]]:+def extract_entities_with_llm(text: str, source_doc: str, model: str = "llama3.2") -> Tuple[List[Entity], List[Relationship]]:"""Use LLM to extract entities and relationships from text."""extraction_prompt = f"""Analyze the following text and extract:@@ -193,7 +200,7 @@ Respond in JSON format:"""try:- response = ollama.chat(+ response = ollama_client.chat(model=model,messages=[{"role": "user", "content": extraction_prompt}],format="json"@@ -306,7 +313,7 @@ Provide a comprehensive answer with inline citations [1], [2], etc. for each cla"""try:- response = ollama.chat(+ response = ollama_client.chat(model=model,messages=[{"role": "user", "content": answer_prompt}])@@ -314,7 +321,6 @@ Provide a comprehensive answer with inline citations [1], [2], etc. for each clareasoning_trace.append("✅ Generated answer with citations")# Step 5: Extract and verify citations- import recitation_refs = re.findall(r'\[(\d+)\]', answer)for ref in set(citation_refs):