참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1,109 @@
{
"version_": "1",
"template_": "SimpleKGPipeline",
"neo4j_config": {
"params_": {
"uri": {
"resolver_": "ENV",
"var_": "NEO4J_URI"
},
"user": {
"resolver_": "ENV",
"var_": "NEO4J_USER"
},
"password": {
"resolver_": "ENV",
"var_": "NEO4J_PASSWORD"
}
}
},
"llm_config": {
"class_": "OpenAILLM",
"params_": {
"api_key": {
"resolver_": "ENV",
"var_": "OPENAI_API_KEY"
},
"model_name": "gpt-5"
}
},
"embedder_config": {
"class_": "OpenAIEmbeddings",
"params_": {
"api_key": {
"resolver_": "ENV",
"var_": "OPENAI_API_KEY"
}
}
},
"from_file": false,
"schema": {
"node_types": [
"Person",
{
"label": "House",
"description": "Family the person belongs to",
"properties": [
{
"name": "name",
"type": "STRING"
}
]
},
{
"label": "Planet",
"properties": [
{
"name": "name",
"type": "STRING"
},
{
"name": "weather",
"type": "STRING"
}
]
}
],
"relationship_types": [
"PARENT_OF",
{
"label": "HEIR_OF",
"description": "Used for inheritor relationship between father and sons"
},
{
"label": "RULES",
"properties": [
{
"name": "fromYear",
"type": "INTEGER"
}
]
}
],
"patterns": [
[
"Person",
"PARENT_OF",
"Person"
],
[
"Person",
"HEIR_OF",
"House"
],
[
"House",
"RULES",
"Planet"
]
]
},
"text_splitter": {
"class_": "text_splitters.fixed_size_splitter.FixedSizeSplitter",
"params_": {
"chunk_size": 100,
"chunk_overlap": 10
}
},
"perform_entity_resolution": true
}

View File

@@ -0,0 +1,59 @@
version_: "1"
template_: SimpleKGPipeline
neo4j_config:
params_:
uri:
resolver_: ENV
var_: NEO4J_URI
user:
resolver_: ENV
var_: NEO4J_USER
password:
resolver_: ENV
var_: NEO4J_PASSWORD
llm_config:
class_: OpenAILLM
params_:
api_key:
resolver_: ENV
var_: OPENAI_API_KEY
model_name: gpt-5
embedder_config:
class_: OpenAIEmbeddings
params_:
api_key:
resolver_: ENV
var_: OPENAI_API_KEY
from_file: false
schema:
node_types:
- label: Person
- label: House
description: Family the person belongs to
properties:
- name: name
type: STRING
- label: Planet
properties:
- name: name
type: STRING
- name: weather
type: STRING
relationship_types:
- label: PARENT_OF
- label: HEIR_OF
description: Used for inheritor relationship between father and sons
- label: RULES
properties:
- name: fromYear
type: INTEGER
patterns:
- ["Person", "PARENT_OF", "Person"]
- ["Person", "HEIR_OF", "House"]
- ["House", "RULES", "Planet"]
text_splitter:
class_: text_splitters.fixed_size_splitter.FixedSizeSplitter
params_:
chunk_size: 100
chunk_overlap: 10
perform_entity_resolution: true

View File

@@ -0,0 +1,115 @@
{
"version_": "1",
"template_": "SimpleKGPipeline",
"neo4j_config": {
"params_": {
"uri": {
"resolver_": "ENV",
"var_": "NEO4J_URI"
},
"user": {
"resolver_": "ENV",
"var_": "NEO4J_USER"
},
"password": {
"resolver_": "ENV",
"var_": "NEO4J_PASSWORD"
}
}
},
"llm_config": {
"class_": "OpenAILLM",
"params_": {
"api_key": {
"resolver_": "ENV",
"var_": "OPENAI_API_KEY"
},
"model_name": "gpt-5"
}
},
"embedder_config": {
"class_": "OpenAIEmbeddings",
"params_": {
"api_key": {
"resolver_": "ENV",
"var_": "OPENAI_API_KEY"
}
}
},
"from_file": true,
"schema": {
"node_types": [
"Person",
{
"label": "House",
"description": "Family the person belongs to",
"properties": [
{
"name": "name",
"type": "STRING"
}
]
},
{
"label": "Planet",
"properties": [
{
"name": "name",
"type": "STRING"
},
{
"name": "weather",
"type": "STRING"
}
]
}
],
"relationship_types": [
"PARENT_OF",
{
"label": "HEIR_OF",
"description": "Used for inheritor relationship between father and sons"
},
{
"label": "RULES",
"properties": [
{
"name": "fromYear",
"type": "INTEGER"
}
]
}
],
"patterns": [
[
"Person",
"PARENT_OF",
"Person"
],
[
"Person",
"HEIR_OF",
"House"
],
[
"House",
"RULES",
"Planet"
]
]
},
"text_splitter": {
"class_": "text_splitters.fixed_size_splitter.FixedSizeSplitter",
"params_": {
"chunk_size": 100,
"chunk_overlap": 10
}
},
"file_loader": {
"class_": "data_loader.PdfLoader",
"run_params_": {
"fs": "http"
}
},
"perform_entity_resolution": true
}

View File

@@ -0,0 +1,47 @@
"""In this example, the pipeline is defined in a JSON ('simple_kg_pipeline_config.json')
or YAML ('simple_kg_pipeline_config.yaml') file.
According to the configuration file, some parameters will be read from the env vars
(Neo4j credentials and the OpenAI API key).
"""
import asyncio
import logging
## If env vars are in a .env file, uncomment:
## (requires pip install python-dotenv)
# from dotenv import load_dotenv
# load_dotenv()
# env vars manually set for testing:
import os
from pathlib import Path
from neo4j_graphrag.experimental.pipeline.config.runner import PipelineRunner
from neo4j_graphrag.experimental.pipeline.pipeline import PipelineResult
logging.basicConfig()
logging.getLogger("neo4j_graphrag").setLevel(logging.DEBUG)
os.environ["NEO4J_URI"] = "bolt://localhost:7687"
os.environ["NEO4J_USER"] = "neo4j"
os.environ["NEO4J_PASSWORD"] = "password"
# os.environ["OPENAI_API_KEY"] = "sk-..."
root_dir = Path(__file__).parent
file_path = root_dir / "simple_kg_pipeline_config.yaml"
# file_path = root_dir / "simple_kg_pipeline_config.json"
# Text to process
TEXT = """The son of Duke Leto Atreides and the Lady Jessica, Paul is the heir of House Atreides,
an aristocratic family that rules the planet Caladan, the rainy planet, since 10191."""
async def main() -> PipelineResult:
pipeline = PipelineRunner.from_config_file(file_path)
return await pipeline.run({"text": TEXT})
if __name__ == "__main__":
print(asyncio.run(main()))

View File

@@ -0,0 +1,45 @@
"""In this example, the pipeline is defined in a JSON ('simple_kg_pipeline_config.json')
or YAML ('simple_kg_pipeline_config.yaml') file.
According to the configuration file, some parameters will be read from the env vars
(Neo4j credentials and the OpenAI API key).
"""
import asyncio
import logging
## If env vars are in a .env file, uncomment:
## (requires pip install python-dotenv)
# from dotenv import load_dotenv
# load_dotenv()
# env vars manually set for testing:
import os
from pathlib import Path
from neo4j_graphrag.experimental.pipeline.config.runner import PipelineRunner
from neo4j_graphrag.experimental.pipeline.pipeline import PipelineResult
logging.basicConfig()
logging.getLogger("neo4j_graphrag").setLevel(logging.DEBUG)
os.environ["NEO4J_URI"] = "bolt://localhost:7687"
os.environ["NEO4J_USER"] = "neo4j"
os.environ["NEO4J_PASSWORD"] = "password"
# os.environ["OPENAI_API_KEY"] = "sk-..."
root_dir = Path(__file__).parent
file_path = root_dir / "simple_kg_pipeline_config_url.json"
# File to process
URL = "https://raw.githubusercontent.com/neo4j/neo4j-graphrag-python/c166afc4d5abc56a5686f3da46a97ed7c07da19d/examples/data/Harry%20Potter%20and%20the%20Chamber%20of%20Secrets%20Summary.pdf"
async def main() -> PipelineResult:
pipeline = PipelineRunner.from_config_file(file_path)
return await pipeline.run({"file_path": URL})
if __name__ == "__main__":
print(asyncio.run(main()))