Skip to content

Commit 0e791eb

Browse files
authored
Merge pull request #122 from mengnankkkk/feat-24-A
feat(vectorstore):add new ARangoDB
2 parents 65b51eb + 4195c1f commit 0e791eb

File tree

16 files changed

+4481
-0
lines changed

16 files changed

+4481
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.alibaba</groupId>
8+
<artifactId>ali-langengine</artifactId>
9+
<version>1.2.6-202508111516</version>
10+
<relativePath>../../../ali-langengine/pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>ali-langengine-arangodb</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.alibaba</groupId>
24+
<artifactId>ali-langengine-core</artifactId>
25+
<version>1.2.6-202508111516</version>
26+
</dependency>
27+
28+
<!-- ArangoDB Java Driver -->
29+
<dependency>
30+
<groupId>com.arangodb</groupId>
31+
<artifactId>arangodb-java-driver</artifactId>
32+
<version>7.1.0</version>
33+
</dependency>
34+
35+
<!-- Jackson for JSON processing -->
36+
<dependency>
37+
<groupId>com.fasterxml.jackson.core</groupId>
38+
<artifactId>jackson-databind</artifactId>
39+
<version>2.15.2</version>
40+
</dependency>
41+
42+
<!-- Apache Commons Lang for utilities -->
43+
<dependency>
44+
<groupId>org.apache.commons</groupId>
45+
<artifactId>commons-lang3</artifactId>
46+
<version>3.12.0</version>
47+
</dependency>
48+
49+
<!-- Test dependencies - 使用父 pom 中定义的版本 -->
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.mockito</groupId>
58+
<artifactId>mockito-core</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
64+
65+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* Copyright (C) 2024 AIDC-AI
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.alibaba.langengine.arangodb;
17+
18+
import com.alibaba.langengine.core.util.WorkPropertiesUtils;
19+
import lombok.Data;
20+
21+
22+
@Data
23+
public class ArangoDBConfiguration {
24+
25+
/**
26+
* ArangoDB 连接主机
27+
*/
28+
public static final String ARANGODB_HOST = WorkPropertiesUtils.get("arangodb_host", "localhost");
29+
30+
/**
31+
* ArangoDB 连接端口
32+
*/
33+
public static final int ARANGODB_PORT = Integer.parseInt(WorkPropertiesUtils.get("arangodb_port", "8529"));
34+
35+
/**
36+
* ArangoDB 用户名
37+
*/
38+
public static final String ARANGODB_USERNAME = WorkPropertiesUtils.get("arangodb_username", "root");
39+
40+
/**
41+
* ArangoDB 密码
42+
*/
43+
public static final String ARANGODB_PASSWORD = WorkPropertiesUtils.get("arangodb_password", "");
44+
45+
/**
46+
* ArangoDB 数据库名称
47+
*/
48+
public static final String ARANGODB_DATABASE = WorkPropertiesUtils.get("arangodb_database", "langengine");
49+
50+
/**
51+
* 默认向量维度
52+
*/
53+
public static final int DEFAULT_VECTOR_DIMENSION = 768;
54+
55+
/**
56+
* 默认相似度阈值
57+
*/
58+
public static final double DEFAULT_SIMILARITY_THRESHOLD = 0.7;
59+
60+
/**
61+
* 默认批处理大小
62+
*/
63+
public static final int DEFAULT_BATCH_SIZE = 100;
64+
65+
/**
66+
* 默认最大缓存大小
67+
*/
68+
public static final int DEFAULT_MAX_CACHE_SIZE = 1000;
69+
70+
/**
71+
* 连接超时时间(毫秒)
72+
*/
73+
public static final int DEFAULT_TIMEOUT_MS = 30000;
74+
75+
/**
76+
* 默认相似度距离函数
77+
*/
78+
public static final String DEFAULT_DISTANCE_FUNCTION = "COSINE";
79+
80+
/**
81+
* 默认集合名称前缀
82+
*/
83+
public static final String DEFAULT_COLLECTION_PREFIX = "vectors_";
84+
85+
/**
86+
* 默认索引名称后缀
87+
*/
88+
public static final String DEFAULT_INDEX_SUFFIX = "_vector_idx";
89+
90+
// 实例配置字段
91+
private String host = ARANGODB_HOST;
92+
private int port = ARANGODB_PORT;
93+
private String username = ARANGODB_USERNAME;
94+
private String password = ARANGODB_PASSWORD;
95+
private String database = ARANGODB_DATABASE;
96+
private int vectorDimension = DEFAULT_VECTOR_DIMENSION;
97+
private double similarityThreshold = DEFAULT_SIMILARITY_THRESHOLD;
98+
private int batchSize = DEFAULT_BATCH_SIZE;
99+
private int maxCacheSize = DEFAULT_MAX_CACHE_SIZE;
100+
private int timeoutMs = DEFAULT_TIMEOUT_MS;
101+
private String distanceFunction = DEFAULT_DISTANCE_FUNCTION;
102+
103+
/**
104+
* 构造函数
105+
*/
106+
public ArangoDBConfiguration() {}
107+
108+
/**
109+
* 带参数的构造函数
110+
*/
111+
public ArangoDBConfiguration(String host, int port, String username, String password, String database) {
112+
this.host = host;
113+
this.port = port;
114+
this.username = username;
115+
this.password = password;
116+
this.database = database;
117+
}
118+
119+
/**
120+
* 验证配置
121+
*/
122+
public void validate() {
123+
if (host == null || host.trim().isEmpty()) {
124+
throw new IllegalArgumentException("ArangoDB host cannot be null or empty");
125+
}
126+
if (port <= 0 || port > 65535) {
127+
throw new IllegalArgumentException("ArangoDB port must be between 1 and 65535");
128+
}
129+
if (username == null || username.trim().isEmpty()) {
130+
throw new IllegalArgumentException("ArangoDB username cannot be null or empty");
131+
}
132+
if (database == null || database.trim().isEmpty()) {
133+
throw new IllegalArgumentException("ArangoDB database cannot be null or empty");
134+
}
135+
if (vectorDimension <= 0) {
136+
throw new IllegalArgumentException("Vector dimension must be positive");
137+
}
138+
if (similarityThreshold < 0.0 || similarityThreshold > 1.0) {
139+
throw new IllegalArgumentException("Similarity threshold must be between 0.0 and 1.0");
140+
}
141+
if (batchSize <= 0) {
142+
throw new IllegalArgumentException("Batch size must be positive");
143+
}
144+
if (maxCacheSize <= 0) {
145+
throw new IllegalArgumentException("Max cache size must be positive");
146+
}
147+
if (timeoutMs <= 0) {
148+
throw new IllegalArgumentException("Timeout must be positive");
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)