88from enum import Enum
99from typing import TYPE_CHECKING , ClassVar
1010
11+ from graphrag .vector_stores .azure_ai_search import AzureAISearchVectorStore
12+ from graphrag .vector_stores .cosmosdb import CosmosDBVectorStore
13+ from graphrag .vector_stores .lancedb import LanceDBVectorStore
14+
1115if TYPE_CHECKING :
1216 from collections .abc import Callable
1317
@@ -31,7 +35,7 @@ class VectorStoreFactory:
3135 for individual enforcement of required/optional arguments.
3236 """
3337
34- _vector_store_registry : ClassVar [dict [str , Callable [..., BaseVectorStore ]]] = {}
38+ _registry : ClassVar [dict [str , Callable [..., BaseVectorStore ]]] = {}
3539
3640 @classmethod
3741 def register (
@@ -47,10 +51,7 @@ def register(
4751 ------
4852 TypeError: If creator is a class type instead of a factory function.
4953 """
50- if isinstance (creator , type ):
51- msg = "Registering classes directly is no longer supported. Please provide a factory function instead."
52- raise TypeError (msg )
53- cls ._vector_store_registry [vector_store_type ] = creator
54+ cls ._registry [vector_store_type ] = creator
5455
5556 @classmethod
5657 def create_vector_store (
@@ -70,56 +71,32 @@ def create_vector_store(
7071 ------
7172 ValueError: If the vector store type is not registered.
7273 """
73- vector_store_type_str = (
74+ type_str = (
7475 vector_store_type .value
7576 if isinstance (vector_store_type , VectorStoreType )
7677 else vector_store_type
7778 )
7879
79- if vector_store_type_str not in cls ._vector_store_registry :
80+ if type_str not in cls ._registry :
8081 msg = f"Unknown vector store type: { vector_store_type } "
8182 raise ValueError (msg )
8283
83- return cls ._vector_store_registry [ vector_store_type_str ](** kwargs )
84+ return cls ._registry [ type_str ](** kwargs )
8485
8586 @classmethod
8687 def get_vector_store_types (cls ) -> list [str ]:
8788 """Get the registered vector store implementations."""
88- return list (cls ._vector_store_registry .keys ())
89+ return list (cls ._registry .keys ())
8990
9091 @classmethod
91- def is_supported_vector_store_type (cls , vector_store_type : str ) -> bool :
92+ def is_supported_type (cls , vector_store_type : str ) -> bool :
9293 """Check if the given vector store type is supported."""
93- return vector_store_type in cls ._vector_store_registry
94-
95-
96- # --- Factory functions for built-in vector stores ---
97- def create_lancedb_vector_store (** kwargs ) -> BaseVectorStore :
98- """Create a LanceDB vector store."""
99- from graphrag .vector_stores .lancedb import LanceDBVectorStore
100-
101- return LanceDBVectorStore (** kwargs )
102-
103-
104- def create_azure_ai_search_vector_store (** kwargs ) -> BaseVectorStore :
105- """Create an Azure AI Search vector store."""
106- from graphrag .vector_stores .azure_ai_search import AzureAISearchVectorStore
94+ return vector_store_type in cls ._registry
10795
108- return AzureAISearchVectorStore (** kwargs )
10996
110-
111- def create_cosmosdb_vector_store (** kwargs ) -> BaseVectorStore :
112- """Create a CosmosDB vector store."""
113- from graphrag .vector_stores .cosmosdb import CosmosDBVectorStore
114-
115- return CosmosDBVectorStore (** kwargs )
116-
117-
118- # --- register default implementations ---
119- VectorStoreFactory .register (VectorStoreType .LanceDB .value , create_lancedb_vector_store )
120- VectorStoreFactory .register (
121- VectorStoreType .AzureAISearch .value , create_azure_ai_search_vector_store
122- )
97+ # --- register built-in vector store implementations ---
98+ VectorStoreFactory .register (VectorStoreType .LanceDB .value , LanceDBVectorStore )
12399VectorStoreFactory .register (
124- VectorStoreType .CosmosDB .value , create_cosmosdb_vector_store
100+ VectorStoreType .AzureAISearch .value , AzureAISearchVectorStore
125101)
102+ VectorStoreFactory .register (VectorStoreType .CosmosDB .value , CosmosDBVectorStore )
0 commit comments