From d8c7e45ee19ce0a9f72c3e7ce1bcc04dc80516f5 Mon Sep 17 00:00:00 2001 From: 0007 <0007@qq.com> Date: Wed, 27 Aug 2025 19:57:50 +0800 Subject: [PATCH] Add File --- .../ElasticSearchVectorStoreTest.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 agents-flex-store/agents-flex-store-elasticsearch/src/test/java/com/agentsflex/store/opensearch/ElasticSearchVectorStoreTest.java diff --git a/agents-flex-store/agents-flex-store-elasticsearch/src/test/java/com/agentsflex/store/opensearch/ElasticSearchVectorStoreTest.java b/agents-flex-store/agents-flex-store-elasticsearch/src/test/java/com/agentsflex/store/opensearch/ElasticSearchVectorStoreTest.java new file mode 100644 index 0000000..a911f9b --- /dev/null +++ b/agents-flex-store/agents-flex-store-elasticsearch/src/test/java/com/agentsflex/store/opensearch/ElasticSearchVectorStoreTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023-2025, Agents-Flex (fuhai999@gmail.com). + *
+ * 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.opensearch;
+
+import com.agentsflex.core.document.Document;
+import com.agentsflex.core.llm.embedding.EmbeddingModel;
+import com.agentsflex.core.llm.embedding.EmbeddingOptions;
+import com.agentsflex.core.store.SearchWrapper;
+import com.agentsflex.core.store.StoreOptions;
+import com.agentsflex.core.store.VectorData;
+import com.agentsflex.core.store.exception.StoreException;
+import com.agentsflex.store.elasticsearch.ElasticSearchVectorStore;
+import com.agentsflex.store.elasticsearch.ElasticSearchVectorStoreConfig;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author songyinyin
+ */
+public class ElasticSearchVectorStoreTest {
+
+ private static ElasticSearchVectorStore getVectorStore() {
+ ElasticSearchVectorStoreConfig config = new ElasticSearchVectorStoreConfig();
+ // config.setApiKey("bmtXRVNaRUJNMEZXZzMzcnNvSXk6MlNMVmFnT0hRVVNUSmN3UXpoNWp4Zw==");
+ config.setUsername("elastic");
+ config.setPassword("Dd2024a10");
+ ElasticSearchVectorStore store = new ElasticSearchVectorStore(config);
+ store.setEmbeddingModel(new EmbeddingModel() {
+ @Override
+ public VectorData embed(Document document, EmbeddingOptions options) {
+ VectorData vectorData = new VectorData();
+ vectorData.setVector(new double[]{0, 0});
+ return vectorData;
+ }
+ });
+ return store;
+ }
+
+ @Test(expected = StoreException.class)
+ public void test01() {
+ ElasticSearchVectorStore store = getVectorStore();
+
+ // https://opensearch.org/docs/latest/search-plugins/vector-search/#example
+ List