m97j commited on
Commit
02a8a1c
·
1 Parent(s): 2ce3fdc

fix(config): use computed_field for dynamic path resolution

Browse files
Files changed (1) hide show
  1. core/config.py +20 -3
core/config.py CHANGED
@@ -1,8 +1,9 @@
1
  # core/config.py
2
 
 
3
  from functools import lru_cache
4
 
5
- from pydantic import Field
6
  from pydantic_settings import BaseSettings, SettingsConfigDict
7
 
8
 
@@ -21,11 +22,27 @@ class Settings(BaseSettings):
21
  REPO_ID: str = Field(default="m97j/ke-store", description="Hugging Face repository ID")
22
 
23
  # 2. Storage Settings (Vector DB & RDBMS)
24
- SQLITE_PATH: str = Field(default="{DATA_DIR}/knowledge_base/corpus.sqlite", description="SQLite DB file path")
25
- QDRANT_PATH: str = Field(default="{DATA_DIR}/vector_store/qdrant", description="Qdrant local storage path")
26
  QDRANT_COLLECTION: str = Field(default="knowledge_base", description="Qdrant collection name")
27
  QDRANT_URL: str = Field(default="http://localhost:6333", description="Qdrant server URL (if using client-server mode)")
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # 3. Model Settings (Embedder & Reranker)
30
  EMBEDDER_NAME: str = Field(default="BAAI/bge-m3", description="FlagEmbedding model name")
31
  RERANKER_NAME: str = Field(default="BAAI/bge-reranker-v2-m3", description="Cross-Encoder model name")
 
1
  # core/config.py
2
 
3
+ import os
4
  from functools import lru_cache
5
 
6
+ from pydantic import Field, computed_field
7
  from pydantic_settings import BaseSettings, SettingsConfigDict
8
 
9
 
 
22
  REPO_ID: str = Field(default="m97j/ke-store", description="Hugging Face repository ID")
23
 
24
  # 2. Storage Settings (Vector DB & RDBMS)
 
 
25
  QDRANT_COLLECTION: str = Field(default="knowledge_base", description="Qdrant collection name")
26
  QDRANT_URL: str = Field(default="http://localhost:6333", description="Qdrant server URL (if using client-server mode)")
27
 
28
+ @computed_field
29
+ @property
30
+ def SQLITE_PATH(self) -> str:
31
+ """
32
+ Computed property to ensure that the SQLite path is always correctly resolved based on the DATA_DIR.
33
+ This allows dynamic changes to DATA_DIR without breaking the SQLITE_PATH reference.
34
+ """
35
+ return os.path.join(self.DATA_DIR, "knowledge_base/corpus.sqlite")
36
+
37
+ @computed_field
38
+ @property
39
+ def QDRANT_PATH(self) -> str:
40
+ """
41
+ Computed property to ensure that the Qdrant path is always correctly resolved based on the DATA_DIR.
42
+ This allows dynamic changes to DATA_DIR without breaking the QDRANT_PATH reference.
43
+ """
44
+ return os.path.join(self.DATA_DIR, "vector_store/qdrant")
45
+
46
  # 3. Model Settings (Embedder & Reranker)
47
  EMBEDDER_NAME: str = Field(default="BAAI/bge-m3", description="FlagEmbedding model name")
48
  RERANKER_NAME: str = Field(default="BAAI/bge-reranker-v2-m3", description="Cross-Encoder model name")