Skip to content

Commit e4b430c

Browse files
[Feature] apache#185: Improvement of Prompt Configuration for rag_demo Graph Index generation
1 parent 3e0bf46 commit e4b430c

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

hugegraph-llm/src/hugegraph_llm/config/prompt_config.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,60 @@ class PromptConfig(BasePromptConfig):
4444
extract_graph_prompt: str = """## Main Task
4545
Given the following graph schema and a piece of text, your task is to analyze the text and extract information that fits into the schema's structure, formatting the information into vertices and edges as specified.
4646
47-
## Basic Rules
48-
### Schema Format
47+
## Basic Rules:
48+
### Schema Format:
4949
Graph Schema:
50-
- Vertices: [List of vertex labels and their properties]
51-
- Edges: [List of edge labels, their source and target vertex labels, and properties]
50+
- "vertices": [List of vertex labels and their properties]
51+
- "edges": [List of edge labels, their source and target vertex labels, and properties]
5252
53-
### Content Rule
54-
Please read the provided text carefully and identify any information that corresponds to the vertices and edges defined in the schema. For each piece of information that matches a vertex or edge, format it according to the following JSON structures:
53+
### Content Rule:
54+
Please read the provided text carefully and identify any information that corresponds to the vertices and edges defined in the schema.
55+
You are not allowed to modify the schema contraints. Your task is to format the provided information into the required schema, without missing any keyword.
56+
For each piece of information that matches a vertex or edge, format it strictly according to the following JSON structures:
5557
5658
#### Vertex Format:
5759
{"id":"vertexLabelID:entityName","label":"vertexLabel","type":"vertex","properties":{"propertyName":"propertyValue", ...}}
5860
61+
where:
62+
- "vertexLabelID": int
63+
- "vertexLabel": str
64+
- "entityName": str
65+
- "type": "vertex"
66+
- "properties": dict
67+
5968
#### Edge Format:
60-
{"label":"edgeLabel","type":"edge","outV":"sourceVertexId","outVLabel":"sourceVertexLabel","inV":"targetVertexId","inVLabel":"targetVertexLabel","properties":{"propertyName":"propertyValue",...}}
61-
Also follow the rules:
62-
1. Don't extract property fields or labels that doesn't exist in the given schema
63-
2. Ensure the extracted property set in the same type as the given schema (like 'age' should be a number, 'select' should be a boolean)
64-
3. If there are multiple primary keys, the strategy for generating VID is: vertexlabelID:pk1!pk2!pk3 (pk means primary key, and '!' is the separator)
65-
4. Output in JSON format, only include vertexes and edges & remove empty properties, extracted and formatted based on the text/rules and schema
66-
5. Translate the schema fields into Chinese if the given text is Chinese but the schema is in English (Optional)
67-
68-
## Example
69+
{"id":"vertexlabelID:pk1!pk2!pk3", label":"edgeLabel","type":"edge","outV":"sourceVertexId","outVLabel":"sourceVertexLabel","inV":"targetVertexId","inVLabel":"targetVertexLabel","properties":{"propertyName":"propertyValue",...}}
70+
71+
where:
72+
- "id": int or str (conditional) (optional)
73+
- "edgeLabel": str
74+
- "type": "edge"
75+
- "outV": str
76+
- "outVLabel": str
77+
- "inV": str
78+
- "inVLabel": str
79+
- "properties": dict
80+
- "sourceVertexId": "vertexLabelID:entityName"
81+
- "targetVertexId": "vertexLabelID:entityName"
82+
83+
Strictly follow these rules:
84+
1. Don't extract property fields or labels that doesn't exist in the given schema. Do not generate new information.
85+
2. Ensure the extracted property set in the same type as the given schema (like 'age' should be a number, 'select' should be a boolean).
86+
3. If there are multiple primary keys, the strategy for generating VID is: vertexlabelID:pk1!pk2!pk3 (pk means primary key, and '!' is the separator). This id must be generated ONLY if there are multiple primary keys. If there is only one primary key, the strategy for generating VID is: int (sequencially increasing).
87+
4. Output in JSON format, only include vertexes and edges & remove empty properties, extracted and formatted based on the text/rules and schema.
88+
5. Translate the schema fields into Chinese if the given text input is Chinese, even if the given schema is in English. (Optional)
89+
90+
Refer to the following baseline example to understand the output generation requirements:
91+
## Example:
6992
### Input example:
70-
#### text
93+
#### text:
7194
Meet Sarah, a 30-year-old attorney, and her roommate, James, whom she's shared a home with since 2010. James, in his professional life, works as a journalist.
7295
73-
#### graph schema
96+
#### graph schema example:
7497
{"vertices":[{"vertex_label":"person","properties":["name","age","occupation"]}], "edges":[{"edge_label":"roommate", "source_vertex_label":"person","target_vertex_label":"person","properties":["date"]]}
7598
7699
### Output example:
77-
[{"id":"1:Sarah","label":"person","type":"vertex","properties":{"name":"Sarah","age":30,"occupation":"attorney"}},{"id":"1:James","label":"person","type":"vertex","properties":{"name":"James","occupation":"journalist"}},{"label":"roommate","type":"edge","outV":"1:Sarah","outVLabel":"person","inV":"1:James","inVLabel":"person","properties":{"date":"2010"}}]
78-
"""
100+
{"vertices":[{"id":"1:Sarah","label":"person","type":"vertex","properties":{"name":"Sarah","age":30,"occupation":"attorney"}},{"id":"1:James","label":"person","type":"vertex","properties":{"name":"James","occupation":"journalist"}}], "edges":[{"id": 1, "label":"roommate","type":"edge","outV":"1:Sarah","outVLabel":"person","inV":"1:James","inVLabel":"person","properties":{"date":"2010"}}]}"""
79101

80102
graph_schema: str = """{
81103
"vertexlabels": [

0 commit comments

Comments
 (0)