This commit is contained in:
ondal
2025-06-17 12:30:32 +09:00
parent ceb05de7f3
commit 3d3f1e5383
4 changed files with 221 additions and 5 deletions
+61 -1
View File
@@ -1178,4 +1178,64 @@ class VectorService:
return {
'added_count': added_count,
'add_details': add_details
}
}
def get_store_by_id(self, store_id: str) -> Optional[Dict[str, Any]]:
"""
store_id로 특정 매장의 정보를 조회합니다.
Args:
store_id: 조회할 매장 ID
Returns:
매장 정보 딕셔너리 또는 None
"""
try:
if not self.is_ready():
logger.warning("⚠️ VectorService가 준비되지 않음")
return None
logger.info(f"🔍 매장 정보 조회 시작: store_id={store_id}")
# Vector DB에서 해당 store_id로 검색
results = self.collection.get(
where={"store_id": store_id},
include=['documents', 'metadatas', 'ids']
)
if not results or not results.get('metadatas') or not results['metadatas']:
logger.warning(f"❌ 매장 정보를 찾을 수 없음: store_id={store_id}")
return None
# 첫 번째 결과 사용 (store_id는 유니크해야 함)
metadata = results['metadatas'][0]
document = results['documents'][0] if results.get('documents') else None
document_id = results['ids'][0] if results.get('ids') else None
logger.info(f"✅ 매장 정보 조회 성공: {metadata.get('store_name', 'Unknown')}")
# 문서에서 JSON 파싱 (combine_store_and_reviews 형태로 저장되어 있음)
store_data = None
if document:
try:
import json
store_data = json.loads(document)
except json.JSONDecodeError as e:
logger.error(f"❌ JSON 파싱 실패: {e}")
return None
# 응답 데이터 구성
result = {
"metadata": metadata,
"document_id": document_id,
"store_info": store_data.get('store_info') if store_data else None,
"reviews": store_data.get('reviews', []) if store_data else [],
"review_summary": store_data.get('review_summary', {}) if store_data else {},
"combined_at": store_data.get('combined_at') if store_data else None
}
return result
except Exception as e:
logger.error(f"❌ 매장 정보 조회 실패: store_id={store_id}, error={e}")
return None