Skip to content

Commit 72484f1

Browse files
committed
Merge branch 'v3/main' into graphrag-config
2 parents 4ad1d01 + 6b03af6 commit 72484f1

File tree

20 files changed

+76
-29
lines changed

20 files changed

+76
-29
lines changed

docs/examples_notebooks/api_overview.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
"from pathlib import Path\n",
2929
"from pprint import pprint\n",
3030
"\n",
31-
"import graphrag.api as api\n",
3231
"import pandas as pd\n",
3332
"from graphrag.config.load_config import load_config\n",
34-
"from graphrag.index.typing.pipeline_run_result import PipelineRunResult"
33+
"from graphrag.index.typing.pipeline_run_result import PipelineRunResult\n",
34+
"\n",
35+
"import graphrag.api as api"
3536
]
3637
},
3738
{

docs/examples_notebooks/input_documents.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
"from pathlib import Path\n",
3131
"from pprint import pprint\n",
3232
"\n",
33-
"import graphrag.api as api\n",
3433
"import pandas as pd\n",
3534
"from graphrag.config.load_config import load_config\n",
36-
"from graphrag.index.typing.pipeline_run_result import PipelineRunResult"
35+
"from graphrag.index.typing.pipeline_run_result import PipelineRunResult\n",
36+
"\n",
37+
"import graphrag.api as api"
3738
]
3839
},
3940
{
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# GraphRAG Factory
1+
# GraphRAG Common
2+
3+
## Factory module
24

35
```python
46
from abc import ABC, abstractmethod
57

6-
from graphrag_factory import Factory
8+
from graphrag_common.factory import Factory
79

810
class SampleABC(ABC):
911

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2024 Microsoft Corporation.
2+
# Licensed under the MIT License
3+
4+
"""GraphRAG Common package."""

packages/graphrag-factory/graphrag_factory/__init__.py renamed to packages/graphrag-common/graphrag_common/factory/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (c) 2024 Microsoft Corporation.
22
# Licensed under the MIT License
33

4-
"""The GraphRAG Factory package."""
4+
"""The GraphRAG factory module."""
55

6-
from graphrag_factory.factory import Factory
6+
from graphrag_common.factory.factory import Factory
77

88
__all__ = ["Factory"]

packages/graphrag-factory/graphrag_factory/factory.py renamed to packages/graphrag-common/graphrag_common/factory/factory.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,27 @@
55

66
from abc import ABC
77
from collections.abc import Callable
8+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
9+
========
10+
from dataclasses import dataclass
11+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
812
from typing import Any, ClassVar, Generic, Literal, TypeVar
913

1014
T = TypeVar("T", covariant=True)
1115

1216
ServiceScope = Literal["singleton", "transient"]
1317

18+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
19+
========
20+
21+
@dataclass
22+
class _ServiceDescriptor(Generic[T]):
23+
"""Descriptor for a service."""
24+
25+
scope: ServiceScope
26+
initializer: Callable[..., T]
27+
28+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
1429

1530
class Factory(ABC, Generic[T]):
1631
"""Abstract base class for factories."""
@@ -25,9 +40,13 @@ def __new__(cls, *args: Any, **kwargs: Any) -> "Factory":
2540

2641
def __init__(self):
2742
if not hasattr(self, "_initialized"):
43+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
2844
self._service_initializers: dict[
2945
str, tuple[ServiceScope, Callable[..., T]]
3046
] = {}
47+
========
48+
self._service_initializers: dict[str, _ServiceDescriptor[T]] = {}
49+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
3150
self._initialized_services: dict[str, T] = {}
3251
self._initialized = True
3352

@@ -54,7 +73,11 @@ def register(
5473
initializer: A callable that creates an instance of T.
5574
scope: The service scope, either 'singleton' or 'transient'.
5675
"""
76+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
5777
self._service_initializers[strategy] = (scope, initializer)
78+
========
79+
self._service_initializers[strategy] = _ServiceDescriptor(scope, initializer)
80+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
5881

5982
def create(self, strategy: str, init_args: dict[str, Any] | None = None) -> T:
6083
"""
@@ -77,12 +100,23 @@ def create(self, strategy: str, init_args: dict[str, Any] | None = None) -> T:
77100
msg = f"Strategy '{strategy}' is not registered. Registered strategies are: {', '.join(list(self._service_initializers.keys()))}"
78101
raise ValueError(msg)
79102

103+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
80104
scope, service_initializer = self._service_initializers[strategy]
81105
if scope == "singleton":
82106
if strategy not in self._initialized_services:
83107
self._initialized_services[strategy] = service_initializer(
108+
========
109+
service_descriptor = self._service_initializers[strategy]
110+
if service_descriptor.scope == "singleton":
111+
if strategy not in self._initialized_services:
112+
self._initialized_services[strategy] = service_descriptor.initializer(
113+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
84114
**(init_args or {})
85115
)
86116
return self._initialized_services[strategy]
87117

118+
<<<<<<<< HEAD:packages/graphrag-factory/graphrag_factory/factory.py
88119
return service_initializer(**(init_args or {}))
120+
========
121+
return service_descriptor.initializer(**(init_args or {}))
122+
>>>>>>>> v3/main:packages/graphrag-common/graphrag_common/factory/factory.py
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
2-
name = "graphrag-factory"
2+
name = "graphrag-common"
33
version = "2.7.0"
4-
description = "GraphRAG: A graph-based retrieval-augmented generation (RAG) system."
4+
description = "Common utilities and types for GraphRAG"
55
authors = [
66
{name = "Alonso Guevara Fernández", email = "[email protected]"},
77
{name = "Andrés Morales Esquivel", email = "[email protected]"},

packages/graphrag/graphrag/cache/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
from graphrag_factory import Factory
8+
from graphrag_common.factory import Factory
99

1010
from graphrag.cache.json_pipeline_cache import JsonPipelineCache
1111
from graphrag.cache.memory_pipeline_cache import InMemoryCache

packages/graphrag/graphrag/index/input/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import logging
77

8-
from graphrag_factory import Factory
8+
from graphrag_common.factory import Factory
99

1010
from graphrag.config.enums import InputFileType
1111
from graphrag.index.input.csv import CSVFileReader

0 commit comments

Comments
 (0)