3131)
3232from graphrag .config .models .text_embedding_config import TextEmbeddingConfig
3333from graphrag .config .models .umap_config import UmapConfig
34+ from graphrag .config .models .vector_store_config import VectorStoreConfig
35+ from graphrag .vector_stores .factory import VectorStoreType
3436
3537
3638class GraphRagConfig (BaseModel ):
@@ -51,11 +53,13 @@ def __str__(self):
5153 def _validate_root_dir (self ) -> None :
5254 """Validate the root directory."""
5355 if self .root_dir .strip () == "" :
54- self .root_dir = str (Path .cwd (). resolve () )
56+ self .root_dir = str (Path .cwd ())
5557
56- if not Path (self .root_dir ).is_dir ():
58+ root_dir = Path (self .root_dir ).resolve ()
59+ if not root_dir .is_dir ():
5760 msg = f"Invalid root directory: { self .root_dir } is not a directory."
5861 raise FileNotFoundError (msg )
62+ self .root_dir = str (root_dir )
5963
6064 models : dict [str , LanguageModelConfig ] = Field (
6165 description = "Available language model configurations." ,
@@ -85,17 +89,50 @@ def _validate_models(self) -> None:
8589 )
8690 """The reporting configuration."""
8791
92+ def _validate_reporting_base_dir (self ) -> None :
93+ """Validate the reporting base directory."""
94+ if self .reporting .type == defs .ReportingType .file :
95+ if self .reporting .base_dir .strip () == "" :
96+ msg = "Reporting base directory is required for file reporting. Please rerun `graphrag init` and set the reporting configuration."
97+ raise ValueError (msg )
98+ self .reporting .base_dir = str (
99+ (Path (self .root_dir ) / self .reporting .base_dir ).resolve ()
100+ )
101+
88102 storage : StorageConfig = Field (
89103 description = "The storage configuration." , default = StorageConfig ()
90104 )
91105 """The storage configuration."""
92106
107+ def _validate_storage_base_dir (self ) -> None :
108+ """Validate the storage base directory."""
109+ if self .storage .type == defs .StorageType .file :
110+ if self .storage .base_dir .strip () == "" :
111+ msg = "Storage base directory is required for file storage. Please rerun `graphrag init` and set the storage configuration."
112+ raise ValueError (msg )
113+ self .storage .base_dir = str (
114+ (Path (self .root_dir ) / self .storage .base_dir ).resolve ()
115+ )
116+
93117 update_index_storage : StorageConfig | None = Field (
94118 description = "The storage configuration for the updated index." ,
95119 default = None ,
96120 )
97121 """The storage configuration for the updated index."""
98122
123+ def _validate_update_index_storage_base_dir (self ) -> None :
124+ """Validate the update index storage base directory."""
125+ if (
126+ self .update_index_storage
127+ and self .update_index_storage .type == defs .StorageType .file
128+ ):
129+ if self .update_index_storage .base_dir .strip () == "" :
130+ msg = "Update index storage base directory is required for file storage. Please rerun `graphrag init` and set the update index storage configuration."
131+ raise ValueError (msg )
132+ self .update_index_storage .base_dir = str (
133+ (Path (self .root_dir ) / self .update_index_storage .base_dir ).resolve ()
134+ )
135+
99136 cache : CacheConfig = Field (
100137 description = "The cache configuration." , default = CacheConfig ()
101138 )
@@ -187,6 +224,21 @@ def _validate_models(self) -> None:
187224 )
188225 """The basic search configuration."""
189226
227+ vector_store : VectorStoreConfig = Field (
228+ description = "The vector store configuration." , default = VectorStoreConfig ()
229+ )
230+ """The vector store configuration."""
231+
232+ def _validate_vector_store_db_uri (self ) -> None :
233+ """Validate the vector store configuration."""
234+ if self .vector_store .type == VectorStoreType .LanceDB .value :
235+ if self .vector_store .db_uri .strip == "" :
236+ msg = "Vector store URI is required for LanceDB. Please rerun `graphrag init` and set the vector store configuration."
237+ raise ValueError (msg )
238+ self .vector_store .db_uri = str (
239+ (Path (self .root_dir ) / self .vector_store .db_uri ).resolve ()
240+ )
241+
190242 def get_language_model_config (self , model_id : str ) -> LanguageModelConfig :
191243 """Get a model configuration by ID.
192244
@@ -216,4 +268,8 @@ def _validate_model(self):
216268 """Validate the model configuration."""
217269 self ._validate_root_dir ()
218270 self ._validate_models ()
271+ self ._validate_reporting_base_dir ()
272+ self ._validate_storage_base_dir ()
273+ self ._validate_update_index_storage_base_dir ()
274+ self ._validate_vector_store_db_uri ()
219275 return self
0 commit comments