Skip to content

Commit 514e094

Browse files
committed
fix copilot changes
1 parent 255d86e commit 514e094

File tree

5 files changed

+31
-42
lines changed

5 files changed

+31
-42
lines changed

graphrag/cache/factory.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
from typing import TYPE_CHECKING, ClassVar
99

10+
from graphrag.cache.json_pipeline_cache import JsonPipelineCache
11+
from graphrag.cache.memory_pipeline_cache import InMemoryCache
12+
from graphrag.cache.noop_pipeline_cache import NoopPipelineCache
1013
from graphrag.config.enums import CacheType
1114
from graphrag.storage.blob_pipeline_storage import BlobPipelineStorage
1215
from graphrag.storage.cosmosdb_pipeline_storage import CosmosDBPipelineStorage
@@ -17,40 +20,6 @@
1720

1821
from graphrag.cache.pipeline_cache import PipelineCache
1922

20-
from graphrag.cache.json_pipeline_cache import JsonPipelineCache
21-
from graphrag.cache.memory_pipeline_cache import InMemoryCache
22-
from graphrag.cache.noop_pipeline_cache import NoopPipelineCache
23-
24-
25-
def create_noop_cache(**_kwargs) -> PipelineCache:
26-
"""Create a no-op cache implementation."""
27-
return NoopPipelineCache()
28-
29-
30-
def create_memory_cache(**_kwargs) -> PipelineCache:
31-
"""Create an in-memory cache implementation."""
32-
return InMemoryCache()
33-
34-
35-
def create_file_cache(root_dir: str, base_dir: str, **kwargs) -> PipelineCache:
36-
"""Create a file-based cache implementation."""
37-
# Create storage with base_dir in kwargs since FilePipelineStorage expects it there
38-
storage_kwargs = {"base_dir": root_dir, **kwargs}
39-
storage = FilePipelineStorage(**storage_kwargs).child(base_dir)
40-
return JsonPipelineCache(storage)
41-
42-
43-
def create_blob_cache(**kwargs) -> PipelineCache:
44-
"""Create a blob storage-based cache implementation."""
45-
storage = BlobPipelineStorage(**kwargs)
46-
return JsonPipelineCache(storage)
47-
48-
49-
def create_cosmosdb_cache(**kwargs) -> PipelineCache:
50-
"""Create a CosmosDB-based cache implementation."""
51-
storage = CosmosDBPipelineStorage(**kwargs)
52-
return JsonPipelineCache(storage)
53-
5423

5524
class CacheFactory:
5625
"""A factory class for cache implementations.
@@ -69,7 +38,7 @@ def register(cls, cache_type: str, creator: Callable[..., PipelineCache]) -> Non
6938
7039
Args:
7140
cache_type: The type identifier for the cache.
72-
creator: A callable that creates an instance of the cache.
41+
creator: A class or callable that creates an instance of PipelineCache.
7342
7443
Raises
7544
------
@@ -100,7 +69,7 @@ def create_cache(
10069
ValueError: If the cache type is not registered.
10170
"""
10271
if not cache_type or cache_type == CacheType.none:
103-
return create_noop_cache()
72+
return NoopPipelineCache()
10473

10574
type_str = cache_type.value if isinstance(cache_type, CacheType) else cache_type
10675

@@ -126,8 +95,28 @@ def is_supported_type(cls, cache_type: str) -> bool:
12695

12796

12897
# --- register built-in cache implementations ---
129-
CacheFactory.register(CacheType.none.value, create_noop_cache)
130-
CacheFactory.register(CacheType.memory.value, create_memory_cache)
98+
def create_file_cache(root_dir: str, base_dir: str, **kwargs) -> PipelineCache:
99+
"""Create a file-based cache implementation."""
100+
# Create storage with base_dir in kwargs since FilePipelineStorage expects it there
101+
storage_kwargs = {"base_dir": root_dir, **kwargs}
102+
storage = FilePipelineStorage(**storage_kwargs).child(base_dir)
103+
return JsonPipelineCache(storage)
104+
105+
106+
def create_blob_cache(**kwargs) -> PipelineCache:
107+
"""Create a blob storage-based cache implementation."""
108+
storage = BlobPipelineStorage(**kwargs)
109+
return JsonPipelineCache(storage)
110+
111+
112+
def create_cosmosdb_cache(**kwargs) -> PipelineCache:
113+
"""Create a CosmosDB-based cache implementation."""
114+
storage = CosmosDBPipelineStorage(**kwargs)
115+
return JsonPipelineCache(storage)
116+
117+
118+
CacheFactory.register(CacheType.none.value, NoopPipelineCache)
119+
CacheFactory.register(CacheType.memory.value, InMemoryCache)
131120
CacheFactory.register(CacheType.file.value, create_file_cache)
132121
CacheFactory.register(CacheType.blob.value, create_blob_cache)
133122
CacheFactory.register(CacheType.cosmosdb.value, create_cosmosdb_cache)

graphrag/storage/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def register(
3838
3939
Args:
4040
storage_type: The type identifier for the storage.
41-
creator: A callable that creates an instance of the storage.
41+
creator: A class or callable that creates an instance of PipelineStorage.
4242
4343
Raises
4444
------

graphrag/storage/file_pipeline_storage.py

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

4-
"""A module containing 'FileStorage' and 'FilePipelineStorage' models."""
4+
"""File-based Storage implementation of PipelineStorage."""
55

66
import logging
77
import os

graphrag/vector_stores/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def register(
4545
4646
Args:
4747
vector_store_type: The type identifier for the vector store.
48-
creator: A callable that creates an instance of the vector store.
48+
creator: A class or callable that creates an instance of BaseVectorStore.
4949
5050
Raises
5151
------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Copyright (c) 2024 Microsoft Corporation.
2-
# Licensed under the MIT License
2+
# Licensed under the MIT License

0 commit comments

Comments
 (0)