/*
* Copyright (c) 2023-2025, Agents-Flex ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agentsflex.store.qcloud;
import com.agentsflex.core.document.Document;
import com.agentsflex.core.llm.client.HttpClient;
import com.agentsflex.core.store.DocumentStore;
import com.agentsflex.core.store.SearchWrapper;
import com.agentsflex.core.store.StoreOptions;
import com.agentsflex.core.store.StoreResult;
import com.agentsflex.core.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.LoggerFactory;
import java.util.*;
/**
* doc https://cloud.tencent.com/document/product/1709/95121
*/
public class QCloudVectorStore extends DocumentStore {
private QCloudVectorStoreConfig config;
private final HttpClient httpUtil = new HttpClient();
public QCloudVectorStore(QCloudVectorStoreConfig config) {
this.config = config;
}
@Override
public StoreResult storeInternal(List documents, StoreOptions options) {
if (documents == null || documents.isEmpty()) {
return StoreResult.success();
}
Map headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer account=" + config.getAccount() + "&api_key=" + config.getApiKey());
Map payloadMap = new HashMap<>();
payloadMap.put("database", config.getDatabase());
payloadMap.put("collection", options.getCollectionNameOrDefault(config.getDefaultCollectionName()));
List