Skip to content

Commit 576a661

Browse files
fix(qdrant): usa default_factory per leggere QDRANT_API_KEY e corregge tutti i comandi per usare config.qdrant.api_key
1 parent 88979ad commit 576a661

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

lib/config.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,19 @@ def set_url_from_env(cls, v):
5858
return v
5959

6060

61+
def _get_qdrant_url():
62+
return os.getenv('QDRANT_URL', 'http://localhost:6333')
63+
64+
def _get_qdrant_api_key():
65+
return os.getenv('QDRANT_API_KEY')
66+
6167
class QdrantConfig(BaseModel):
6268
"""Configuration for Qdrant vector database."""
6369

6470
collection: str = Field(default="documentation", description="Collection name")
6571
batch_size: int = Field(default=10, description="Batch upload size")
66-
url: Optional[str] = Field(default=None, description="Qdrant URL")
67-
api_key: Optional[str] = Field(default=None, description="API key if required")
68-
69-
@field_validator('url', mode='before')
70-
@classmethod
71-
def set_url_from_env(cls, v):
72-
"""Set URL from environment if not provided."""
73-
if v is None or v == '':
74-
return os.getenv('QDRANT_URL', 'http://localhost:6333')
75-
return v
76-
77-
@field_validator('api_key', mode='before')
78-
@classmethod
79-
def set_api_key_from_env(cls, v):
80-
"""Set API key from environment if not provided."""
81-
if v is None or v == '':
82-
return os.getenv('QDRANT_API_KEY')
83-
return v
72+
url: str = Field(default_factory=_get_qdrant_url, description="Qdrant URL")
73+
api_key: Optional[str] = Field(default_factory=_get_qdrant_api_key, description="API key if required")
8474

8575

8676
class ProcessingConfig(BaseModel):

ragify.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,10 @@ def main():
606606
from qdrant_client import QdrantClient
607607
from qdrant_client.http import models
608608

609-
client = QdrantClient(url=os.getenv('QDRANT_URL', 'http://localhost:6333'))
609+
client = QdrantClient(
610+
url=config.qdrant.url,
611+
api_key=config.qdrant.api_key
612+
)
610613

611614
results = client.query_points(
612615
collection_name=collection,
@@ -651,7 +654,10 @@ def main():
651654

652655
try:
653656
from qdrant_client import QdrantClient
654-
client = QdrantClient(url=os.getenv('QDRANT_URL', 'http://localhost:6333'))
657+
client = QdrantClient(
658+
url=config.qdrant.url,
659+
api_key=config.qdrant.api_key
660+
)
655661

656662
# Get collection info
657663
collection_info = client.get_collection(collection)
@@ -719,7 +725,17 @@ def main():
719725
from qdrant_client import QdrantClient
720726
from qdrant_client.http import models
721727

722-
client = QdrantClient(url=os.getenv('QDRANT_URL', 'http://localhost:6333'))
728+
# Load config for API key
729+
config_path = Path('config.yaml')
730+
if config_path.exists():
731+
reset_config = RagifyConfig.load(config_path)
732+
else:
733+
reset_config = RagifyConfig.default()
734+
735+
client = QdrantClient(
736+
url=reset_config.qdrant.url,
737+
api_key=reset_config.qdrant.api_key
738+
)
723739

724740
# Handle --all flag: delete ALL collections
725741
if args.reset_all:

0 commit comments

Comments
 (0)