문서 추가와 검색
문서 추가와 검색
문서는 POST /indexes/{index_name}/documents로 넣어요. 임베딩할 필드는 tensor_fields로 지정해요.
curl -X POST "http://localhost:8882/indexes/test-index/documents" \
-H "Content-Type: application/json" \
-d '{
"documents": [
{"_id": "1", "text": "The Eiffel Tower is a famous landmark in France"},
{"_id": "2", "text": "The Colosseum is a historic landmark in Italy"}
],
"tensor_fields": ["text"]
}'
문서를 넣으면 임베딩이 자동 생성되고, 검색은 POST /indexes/{index_name}/search로 해요. q에 질의를 넘기면 의미적으로 가장 관련 높은 문서가 정렬돼 돌아와요.
curl -X POST "http://localhost:8882/indexes/test-index/search" \
-H "Content-Type: application/json" \
-d '{"q": "famous landmark in France"}'
{
"hits": [
{"_id": "1", "text": "The Eiffel Tower is a famous landmark in France"}
],
"query": "famous landmark in France",
"limit": 10,
"offset": 0,
"processingTimeMs": 78
}
"Eiffel Tower"라는 단어가 질의에 없는데도 "famous landmark in France"라는 의미로 가장 관련 높은 문서를 찾아내는 걸 볼 수 있어요. 이게 벡터 검색의 핵심 장점이에요.