|
25 | 25 | "metadata": {}, |
26 | 26 | "outputs": [], |
27 | 27 | "source": [ |
28 | | - "import graphrag.api as api\n", |
29 | | - "from graphrag.index.typing import PipelineRunResult" |
30 | | - ] |
31 | | - }, |
32 | | - { |
33 | | - "cell_type": "markdown", |
34 | | - "metadata": {}, |
35 | | - "source": [ |
36 | | - "## Prerequisite\n", |
37 | | - "As a prerequisite to all API operations, a `GraphRagConfig` object is required. It is the primary means to control the behavior of graphrag and can be instantiated from a `settings.yaml` configuration file.\n", |
| 28 | + "from pathlib import Path\n", |
| 29 | + "from pprint import pprint\n", |
38 | 30 | "\n", |
39 | | - "Please refer to the [CLI docs](https://microsoft.github.io/graphrag/cli/#init) for more detailed information on how to generate the `settings.yaml` file.\n", |
| 31 | + "import pandas as pd\n", |
40 | 32 | "\n", |
41 | | - "#### Load `settings.yaml` configuration" |
| 33 | + "import graphrag.api as api\n", |
| 34 | + "from graphrag.config.load_config import load_config\n", |
| 35 | + "from graphrag.index.typing.pipeline_run_result import PipelineRunResult" |
42 | 36 | ] |
43 | 37 | }, |
44 | 38 | { |
|
47 | 41 | "metadata": {}, |
48 | 42 | "outputs": [], |
49 | 43 | "source": [ |
50 | | - "import yaml\n", |
51 | | - "\n", |
52 | | - "PROJECT_DIRECTORY = \"<project_directory>\"\n", |
53 | | - "settings = yaml.safe_load(open(f\"{PROJECT_DIRECTORY}/settings.yaml\")) # noqa: PTH123, SIM115" |
| 44 | + "PROJECT_DIRECTORY = \"<your project directory>\"" |
54 | 45 | ] |
55 | 46 | }, |
56 | 47 | { |
57 | 48 | "cell_type": "markdown", |
58 | 49 | "metadata": {}, |
59 | 50 | "source": [ |
60 | | - "At this point, you can modify the imported settings to align with your application's requirements. For example, if building a UI application, the application might need to change the input and/or storage destinations dynamically in order to enable users to build and query different indexes." |
| 51 | + "## Prerequisite\n", |
| 52 | + "As a prerequisite to all API operations, a `GraphRagConfig` object is required. It is the primary means to control the behavior of graphrag and can be instantiated from a `settings.yaml` configuration file.\n", |
| 53 | + "\n", |
| 54 | + "Please refer to the [CLI docs](https://microsoft.github.io/graphrag/cli/#init) for more detailed information on how to generate the `settings.yaml` file." |
61 | 55 | ] |
62 | 56 | }, |
63 | 57 | { |
|
73 | 67 | "metadata": {}, |
74 | 68 | "outputs": [], |
75 | 69 | "source": [ |
76 | | - "from graphrag.config.create_graphrag_config import create_graphrag_config\n", |
77 | | - "\n", |
78 | | - "graphrag_config = create_graphrag_config(values=settings, root_dir=PROJECT_DIRECTORY)" |
| 70 | + "graphrag_config = load_config(Path(PROJECT_DIRECTORY))" |
79 | 71 | ] |
80 | 72 | }, |
81 | 73 | { |
|
123 | 115 | "metadata": {}, |
124 | 116 | "outputs": [], |
125 | 117 | "source": [ |
126 | | - "import pandas as pd\n", |
127 | | - "\n", |
128 | | - "final_entities = pd.read_parquet(f\"{PROJECT_DIRECTORY}/output/entities.parquet\")\n", |
129 | | - "final_communities = pd.read_parquet(f\"{PROJECT_DIRECTORY}/output/communities.parquet\")\n", |
130 | | - "final_community_reports = pd.read_parquet(\n", |
| 118 | + "entities = pd.read_parquet(f\"{PROJECT_DIRECTORY}/output/entities.parquet\")\n", |
| 119 | + "communities = pd.read_parquet(f\"{PROJECT_DIRECTORY}/output/communities.parquet\")\n", |
| 120 | + "community_reports = pd.read_parquet(\n", |
131 | 121 | " f\"{PROJECT_DIRECTORY}/output/community_reports.parquet\"\n", |
132 | 122 | ")\n", |
133 | 123 | "\n", |
134 | 124 | "response, context = await api.global_search(\n", |
135 | 125 | " config=graphrag_config,\n", |
136 | | - " entities=final_entities,\n", |
137 | | - " communities=final_communities,\n", |
138 | | - " community_reports=final_community_reports,\n", |
| 126 | + " entities=entities,\n", |
| 127 | + " communities=communities,\n", |
| 128 | + " community_reports=community_reports,\n", |
139 | 129 | " community_level=2,\n", |
140 | 130 | " dynamic_community_selection=False,\n", |
141 | 131 | " response_type=\"Multiple Paragraphs\",\n", |
|
172 | 162 | "metadata": {}, |
173 | 163 | "outputs": [], |
174 | 164 | "source": [ |
175 | | - "from pprint import pprint\n", |
176 | | - "\n", |
177 | 165 | "pprint(context) # noqa: T203" |
178 | 166 | ] |
179 | 167 | } |
180 | 168 | ], |
181 | 169 | "metadata": { |
182 | 170 | "kernelspec": { |
183 | | - "display_name": "graphrag-venv", |
| 171 | + "display_name": ".venv", |
184 | 172 | "language": "python", |
185 | 173 | "name": "python3" |
186 | 174 | }, |
|
194 | 182 | "name": "python", |
195 | 183 | "nbconvert_exporter": "python", |
196 | 184 | "pygments_lexer": "ipython3", |
197 | | - "version": "3.10.15" |
| 185 | + "version": "3.11.9" |
198 | 186 | } |
199 | 187 | }, |
200 | 188 | "nbformat": 4, |
|
0 commit comments