Skip to content

Commit c873c58

Browse files
edlee123pre-commit-ci[bot]chickenraeashahba
authored
GraphRAG on CPU Example (#2002)
Signed-off-by: Ed Lee <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Rachel R <[email protected]> Co-authored-by: Abolfazl Shahbazi <[email protected]>
1 parent e60951e commit c873c58

File tree

10 files changed

+838
-13
lines changed

10 files changed

+838
-13
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# About GraphRAG LLMs
2+
3+
## Overview
4+
5+
GraphRAG uses three distinct LLMs, each optimized for different tasks in the pipeline:
6+
7+
1. Dataprep LLM
8+
2. Retriever LLM
9+
3. Final LLM
10+
11+
## 1. Dataprep LLM
12+
13+
Used during data ingestion phase to:
14+
15+
- Process and understand document structure
16+
- Extract entities and relationships between entities
17+
- Generate and store community summaries in Neo4j:
18+
19+
```python
20+
# neo4j_llamaindex.py
21+
async def generate_community_summary(self, text):
22+
"""Generate summary for a given text using an LLM."""
23+
messages = [
24+
ChatMessage(
25+
role="system",
26+
content=(
27+
"You are provided with a set of relationships from a knowledge graph... "
28+
"Your task is to create a summary of these relationships..."
29+
),
30+
)
31+
]
32+
response = await self.llm.achat(trimmed_messages)
33+
```
34+
35+
**Key Requirements:**
36+
37+
- High-quality model for accurate relationship understanding
38+
- Larger context window for document processing
39+
- Can be slower since it's one-time processing
40+
41+
## 2. Retriever LLM
42+
43+
Used during query processing to:
44+
45+
- Evaluate relevance of pre-computed community summaries
46+
- Generate specific answers from relevant communities
47+
- Process multiple communities in parallel
48+
49+
```python
50+
def generate_answer_from_summary(self, community_summary, query):
51+
"""Generate an answer from a community summary based on a given query using LLM."""
52+
prompt = (
53+
f"Given the community summary: {community_summary}, "
54+
f"how would you answer the following query? Query: {query}"
55+
)
56+
response = self._llm.chat(messages)
57+
```
58+
59+
**Key Requirements:**
60+
61+
- Fast inference for real-time processing
62+
- Efficient batch processing capabilities
63+
- Balance between quality and speed
64+
65+
## 3. Final LLM
66+
67+
Used as the last step to:
68+
69+
- Process all retriever-generated answers
70+
- Synthesize information from multiple communities
71+
- Generate coherent final response
72+
73+
```python
74+
# In graphrag.py
75+
llm = MicroService(
76+
name="llm",
77+
host=LLM_SERVER_HOST_IP,
78+
port=LLM_SERVER_PORT,
79+
endpoint="/v1/chat/completions",
80+
service_type=ServiceType.LLM,
81+
)
82+
```
83+
84+
**Key Requirements:**
85+
86+
- Good at synthesizing multiple sources
87+
- Strong natural language generation
88+
- Maintains context across multiple inputs
89+
90+
## Data Flow
91+
92+
1. **Ingestion Phase**
93+
94+
- Documents → Dataprep LLM → Community Summaries
95+
- Summaries stored in Neo4j
96+
97+
2. **Query Phase**
98+
- Query → Retriever LLM → Individual Community Answers
99+
- Answers → Final LLM → Coherent Response
100+
101+
## Configuration
102+
103+
Each LLM can be configured independently through environment variables:
104+
105+
- `DATAPREP_LLM_ENDPOINT` and `DATAPREP_LLM_MODEL_ID`
106+
- `RETRIEVER_LLM_ENDPOINT` and `RETRIEVER_LLM_MODEL_ID`
107+
- `FINAL_LLM_ENDPOINT` and `FINAL_LLM_MODEL_ID`
108+
109+
This allows for optimization of each LLM for its specific task in the pipeline.

0 commit comments

Comments
 (0)