Skip to content

Commit

Permalink
[Feature] apache#185: Improvement of Prompt Configuration for rag_dem…
Browse files Browse the repository at this point in the history
…o Graph Index generation
  • Loading branch information
Kryst4lDem0ni4s committed Mar 2, 2025
1 parent 3e0bf46 commit e4b430c
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions hugegraph-llm/src/hugegraph_llm/config/prompt_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,60 @@ class PromptConfig(BasePromptConfig):
extract_graph_prompt: str = """## Main Task
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.
## Basic Rules
### Schema Format
## Basic Rules:
### Schema Format:
Graph Schema:
- Vertices: [List of vertex labels and their properties]
- Edges: [List of edge labels, their source and target vertex labels, and properties]
- "vertices": [List of vertex labels and their properties]
- "edges": [List of edge labels, their source and target vertex labels, and properties]
### Content Rule
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:
### Content Rule:
Please read the provided text carefully and identify any information that corresponds to the vertices and edges defined in the schema.
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.
For each piece of information that matches a vertex or edge, format it strictly according to the following JSON structures:
#### Vertex Format:
{"id":"vertexLabelID:entityName","label":"vertexLabel","type":"vertex","properties":{"propertyName":"propertyValue", ...}}
where:
- "vertexLabelID": int
- "vertexLabel": str
- "entityName": str
- "type": "vertex"
- "properties": dict
#### Edge Format:
{"label":"edgeLabel","type":"edge","outV":"sourceVertexId","outVLabel":"sourceVertexLabel","inV":"targetVertexId","inVLabel":"targetVertexLabel","properties":{"propertyName":"propertyValue",...}}
Also follow the rules:
1. Don't extract property fields or labels that doesn't exist in the given schema
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)
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)
4. Output in JSON format, only include vertexes and edges & remove empty properties, extracted and formatted based on the text/rules and schema
5. Translate the schema fields into Chinese if the given text is Chinese but the schema is in English (Optional)
## Example
{"id":"vertexlabelID:pk1!pk2!pk3", label":"edgeLabel","type":"edge","outV":"sourceVertexId","outVLabel":"sourceVertexLabel","inV":"targetVertexId","inVLabel":"targetVertexLabel","properties":{"propertyName":"propertyValue",...}}
where:
- "id": int or str (conditional) (optional)
- "edgeLabel": str
- "type": "edge"
- "outV": str
- "outVLabel": str
- "inV": str
- "inVLabel": str
- "properties": dict
- "sourceVertexId": "vertexLabelID:entityName"
- "targetVertexId": "vertexLabelID:entityName"
Strictly follow these rules:
1. Don't extract property fields or labels that doesn't exist in the given schema. Do not generate new information.
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).
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).
4. Output in JSON format, only include vertexes and edges & remove empty properties, extracted and formatted based on the text/rules and schema.
5. Translate the schema fields into Chinese if the given text input is Chinese, even if the given schema is in English. (Optional)
Refer to the following baseline example to understand the output generation requirements:
## Example:
### Input example:
#### text
#### text:
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.
#### graph schema
#### graph schema example:
{"vertices":[{"vertex_label":"person","properties":["name","age","occupation"]}], "edges":[{"edge_label":"roommate", "source_vertex_label":"person","target_vertex_label":"person","properties":["date"]]}
### Output example:
[{"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"}}]
"""
{"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"}}]}"""

graph_schema: str = """{
"vertexlabels": [
Expand Down

0 comments on commit e4b430c

Please sign in to comment.