File size: 7,075 Bytes
ec00d51 d5b0a13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | # 3개 컬렉션 호출하는 법 (텍스트 컬렉션 : page, 이미지 - colqwen, 이미지 - tomoro)
# ✅ 1. 텍스트 쿼리 - `page` 컬렉션 검색
### 🟢 1-1. 필터 없이 검색
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "물류업체 선정 기준",
"top_k": 3
}'
```
### 🟢 1-2. 단일 필터 적용
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "DSG",
"top_k": 3,
"filters": {
"apply_region": "2공장"
}
}'
```
### 🟢 1-3. 다중 필터 적용 (AND 조건)
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "DSG 상정반 교체 절차",
"top_k": 3,
"filters": {
"apply_region": "3공장",
"apply_product": "300mm"
}
}'
```
---
# ✅ 2. 텍스트 쿼리 - 이미지 컬렉션 검색 (`Tomoro`)
### 🟡 2-1. 필터 없이 검색
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text/tomoro' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "물류업체 선정 기준",
"top_k": 3
}'
```
### 🟡 2-2. 다중 필터 적용
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text/tomoro' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "출하검사 기준",
"top_k": 3,
"filters": {
"document_type": "지침서",
"apply_product": "지원부문"
}
}'
```
---
## ✅ 3. 텍스트 쿼리 - 이미지 컬렉션 검색 (`ColQwen3.5`)
### 🟢 3-1. 필터 없이 검색
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text/colqwen35' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "안전운전 절차",
"top_k": 3
}'
```
### 🟢 3-2. 다중 필터 적용
```bash
curl -X 'POST' \
'http://10.150.6.47:4275/search/text/colqwen35' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "물류업체 선정 기준",
"top_k": 3,
"filters": {
"apply_region": "전사공통",
"dept_name": "Infra구매팀"
}
}'
```
# 3. 단어 사전
# 단어사전 호출하는 법
```bash
curl -X POST 'http://10.150.6.47:4276/search/term' \
-H 'Content-Type: application/json' \
-d '{
"query": "안전골든룰",
"top_k": 3,
"filters": {
"apply_region": "전사공통",
"document_type": "지침서"
}
}'
```
# 4. 최종 api call
```
import requests
import json
# 🔧 설정
BASE_URL = "http://10.150.6.46:18504" # FastAPI 서버 주소
SEARCH_ENDPOINT = f"{BASE_URL}/search"
# 📝 쿼리 요청 데이터
payload = {
"query": "TTV 규격 기준",
"top_k": 10,
"image_backend": "colqwen35", # 또는 "tomoro"
"alpha_override": None, # 자동으로 query_type 기반 alpha 적용
"filters": {
# 필요 시 필터 추가 (예: 부서, 지역, 제품 등)
# "dept_name": "품질관리팀",
# "apply_region": "Korea"
},
"return_debug": True, # 디버그 정보 포함 (개발용)
"rerank": True # 리랭커 사용 여부 (환경 기본값 따름)
}
# 🌐 요청 보내기
try:
print("🔍 'TTV 규격 기준' 쿼리 전송 중...")
response = requests.post(
SEARCH_ENDPOINT,
json=payload,
timeout=60 # 서버 응답 대기 시간
)
# 🔍 응답 확인
if response.status_code == 200:
result = response.json()
print("\n✅ 성공! 검색 결과:")
print(json.dumps(result, indent=2, ensure_ascii=False))
# 간단히 상위 3개 결과 출력
print("\n📌 상위 3개 결과 요약:")
for i, item in enumerate(result["results"][:3], 1):
rank = item["rank"]
score = item["score"]
rerank_score = item.get("rerank_score")
content = item["content"] or "(내용 없음)"
print(f" {i}. [Rank:{rank}] (Score: {score:.4f}, Rerank: {rerank_score})")
print(f" {content[:150]}...")
else:
print(f"❌ 요청 실패: {response.status_code} - {response.text}")
except requests.exceptions.ConnectionError:
print("🚨 연결 오류: FastAPI 서버가 실행 중인지 확인하세요 (uvicorn 실행 여부)")
except requests.exceptions.Timeout:
print("⏰ 타임아웃: 서버 응답이 지연되고 있습니다.")
except Exception as e:
print(f"💥 예상치 못한 오류: {e}")
```
# VLM API CALL
```python
### H200-2 서버 : Qwen3.5-397B-A17B-FP8
### 이미지 Input
import requests
import base64
import mimetypes
'''
Thinking mode: temperature=0.6, top_p=0.95, top_k=20, min_p=0.0, presence_penalty=0.0, repetition_penalty=1.0
Instruct (or non-thinking) mode: temperature=0.7, top_p=0.8, top_k=20, min_p=0.0, presence_penalty=1.5, repetition_penalty=1.0
'''
def encode_image_to_base64(image_path):
mime_type,_ = mimetypes.guess_type(image_path)
with open(image_path, "rb") as image_file:
base64_encoded = base64.b64encode(image_file.read()).decode("utf-8")
return f"data:{mime_type};base64,{base64_encoded}"
image_path = "./test.png"
image_input = {
"type": "image_url",
"image_url": {
"url": f"{encode_image_to_base64(image_path)}"
}
}
response = requests.post(
"http://10.150.6.160:8000/v1/chat/completions",
json={
"model": "Qwen3.5-397B-A17B-FP8",
'messages':[
{"role":"system", "content":"너는 SK실트론의 AI Assistant입니다."},
{"role":"user", "content":[
image_input,
{"type":"text","text":"이미지 OCR해줘"}
]
}
],
"temperature":0.6,
"top_p":0.95,
"top_k":20,
"min_p":0.0,
"presence_penalty":0.0,
"repetition_penalty":1.0,
}
)
print(response.json()['choices'][0]['message']['content'])
### Non-thinking
response = requests.post(
"http://10.150.6.160:8000/v1/chat/completions",
json={
"model": "Qwen3.5-397B-A17B-FP8",
'messages':[
{"role":"system", "content":"너는 SK실트론의 AI Assistant입니다."},
{"role":"user", "content":[
{"type":"text","text":"안녕하세요."}
]
}
],
"temperature":0.7,
"top_p":0.8,
"top_k":20,
"min_p":0.0,
"presence_penalty":1.5,
"repetition_penalty":1.0,
"chat_template_kwargs": {"enable_thinking": False} ## Thinking(Reasoning) off
}
)
print(response.json()['choices'][0]['message']['content'])
```
|