Skip to content

Commit 7c831de

Browse files
Add schema extraction prompt template
1 parent 8b163e4 commit 7c831de

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/neo4j_graphrag/generation/prompts.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,41 @@ def format(
200200
text: str = "",
201201
) -> str:
202202
return super().format(text=text, schema=schema, examples=examples)
203+
204+
205+
class SchemaExtractionTemplate(PromptTemplate):
206+
DEFAULT_TEMPLATE = """
207+
You are a top-tier algorithm designed for extracting a labeled property graph schema in
208+
structured formats.
209+
210+
Generate the generalized graph schema based on input text. Identify key entity types,
211+
their relationship types, and property types whenever it is possible. Return only
212+
abstract schema information, no concrete instances. Use singular PascalCase labels for
213+
entity types and UPPER_SNAKE_CASE for relationship types. Include property definitions
214+
only when the type can be confidently inferred, otherwise omit the properties.
215+
Accepted property types are: BOOLEAN, DATE, DURATION, FLOAT, INTEGER, LIST,
216+
LOCAL DATETIME, LOCAL TIME, POINT, STRING, ZONED DATETIME, ZONED TIME.
217+
Do not add extra keys or explanatory text. Return a valid JSON object without
218+
back‑ticks, markdown, or comments.
219+
220+
For example, if the text says "Alice lives in London", the output JSON object should
221+
adhere to the following format:
222+
{"entities": [{"label": "Person", "properties": [{"name": "name", "type": "STRING"}]},
223+
{"label": "City", "properties":[{"name": "name", "type": "STRING"}]}],
224+
"relations": [{"label": "LIVES_IN"}],
225+
"potential_schema":[[ "Person", "LIVES_IN", "City"]]}
226+
227+
More examples:
228+
{examples}
229+
230+
Input text:
231+
{text}
232+
"""
233+
EXPECTED_INPUTS = ["text"]
234+
235+
def format(
236+
self,
237+
examples: str,
238+
text: str = "",
239+
) -> str:
240+
return super().format(text=text, examples=examples)

0 commit comments

Comments
 (0)