Java를 활용한 문서 폴더 관리 API
문서 조각 관리
문서 조각 추가
이미 존재하는 DOC_ID
를 사용해 문서 조각을 추가하면 덮어쓰여집니다.
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
public class ApiClient {
private final RestTemplate restTemplate = new RestTemplate();
public void updateDocument(String collectionCode, String docId, String apiKey, String projectCode, String text) {
String url = "https://api-laas.wanted.co.kr/api/document/" + collectionCode + "/" + docId;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("apiKey", apiKey);
headers.set("project", projectCode);
String requestBody = String.format("{\"text\": \"%s\"}", text);
HttpEntity<String--> requestEntity = new HttpEntity<>(requestBody, headers);
restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class);
}
}
문서 조각 조회
public String getDocument(String collectionCode, String docId, String apiKey, String projectCode) {
String url = "https://api-laas.wanted.co.kr/api/document/" + collectionCode + "/" + docId;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("apiKey", apiKey);
headers.set("project", projectCode);
HttpEntity<String--> requestEntity = new HttpEntity<>(headers);
ResponseEntity<string> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
return response.getBody();
}
문서 조각 삭제
public void deleteDocument(String collectionCode, String docId, String apiKey, String projectCode) {
String url = "https://api-laas.wanted.co.kr/api/document/" + collectionCode + "/" + docId;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("apiKey", apiKey);
headers.set("project", projectCode);
HttpEntity<String--> requestEntity = new HttpEntity<>(headers);
restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class);
}
문서 검색
ID 기반 유사도 검색
지정한 DOC_ID
문서와 유사한 문서 조각을 검색합니다.
public String findSimilarDocuments(String collectionCode, String docId, String apiKey, String projectCode, int limit, int offset) {
String url = "https://api-laas.wanted.co.kr/api/document/" + collectionCode + "/similar/" + docId;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("apiKey", apiKey);
headers.set("project", projectCode);
String requestBody = String.format("{\"limit\": %d, \"offset\": %d}", limit, offset);
HttpEntity<String--> requestEntity = new HttpEntity<>(requestBody, headers);
ResponseEntity<string> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
return response.getBody();
}
문자열 기 반 유사도 검색
입력된 텍스트 TEXT
와 유사한 문서를 검색합니다. 임베딩 모델이 사용됩니다.
public String findSimilarDocumentsByText(String collectionCode, String apiKey, String projectCode, String text, int limit, int offset) {
String url = "https://api-laas.wanted.co.kr/api/document/" + collectionCode + "/similar/text";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("apiKey", apiKey);
headers.set("project", projectCode);
String requestBody = String.format("{\"text\": \"%s\", \"limit\": %d, \"offset\": %d}", text, limit, offset);
HttpEntity<String--> requestEntity = new HttpEntity<>(requestBody, headers);
ResponseEntity<string> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
return response.getBody();
}