跳至主要内容
前往文档
⌘U
Weaviate 数据库

使用 Weaviate 的 APIs 和工具开发 AI 应用

部署

部署、配置和维护 Weaviate 数据库

Weaviate Agents

使用 Weaviate 构建和部署智能代理

Weaviate Cloud

在云端管理和扩展 Weaviate

更多资源

集成
贡献者指南
活动 & 工作坊
Weaviate Academy

需要帮助?

Weaviate Logo询问 AI 助手⌘K
社区论坛

Java

Java 客户端 v6

我们已正式发布新的 Java v6 客户端。

与之前的 v5 客户端 API 相比,v6 客户端引入了根本性的变化。我们建议切换到 v6 客户端,因为 v5 客户端将不再支持新的 Weaviate 功能。

Java v6 客户端 (SDK)

最新的 Java v6 客户端版本是 v6.0.0

此页面广泛介绍了 Weaviate Java 客户端 (v6 beta 版本)。有关不特定于 Java 客户端的使用信息,例如代码示例,请参阅 操作指南和指南 中的相关页面。

安装

<dependency>
<groupId>io.weaviate</groupId>
<artifactId>client6</artifactId>
<version>6.0.0</version>
</dependency>
Uber JAR🫙

如果您使用类似 maven-assembly-plugin 的工具构建 uber-JAR,请使用带有分类器 all 的阴影版本。这可确保正确解析 io.grpc 的所有动态加载依赖项。

<dependency>
<groupId>io.weaviate</groupId>
<artifactId>client6</artifactId>
<version>6.0.0</version>
<classifier>all</classifier>
</dependency>
要求:Weaviate 版本兼容性 & gRPC

Weaviate 版本兼容性

v6 Java 客户端需要 Weaviate 1.33.0 或更高版本。通常,我们鼓励您使用最新版本的 Java 客户端和 Weaviate 数据库。

gRPC

v6 客户端在底层使用远程过程调用 (RPC)。因此,必须向您的 Weaviate 服务器打开 gRPC 端口。

docker-compose.yml 示例

如果您使用 Docker 运行 Weaviate,可以通过将以下内容添加到您的 docker-compose.yml 文件中来映射默认端口 (50051)

ports:
- 8080:8080
- 50051:50051

入门

先决条件

如果您尚未这样做,我们建议您首先完成 快速入门教程,以便充分利用本节。

使用此 Java 示例开始使用 Weaviate。该代码将引导您完成以下关键步骤

  1. 连接到 Weaviate:建立到本地(或 Cloud)Weaviate 实例的连接。
  2. 创建集合:定义 Question 集合的数据模式,使用 Ollama 模型对数据进行向量化。
  3. 导入数据:获取示例 Jeopardy 问题,并使用 Weaviate 的批量导入进行高效摄取和自动向量嵌入生成。
  4. 搜索/查询数据库:执行向量搜索,以查找与查询 biology 语义相似的问题。
  // Connect to a local Weaviate instance
client = WeaviateClient.connectToLocal();
if (client.collections.exists(collectionName)) {
client.collections.delete(collectionName);
}

// Create a collection with
client.collections.create(
collectionName,
col -> col.properties(Property.text("answer"),
Property.text("question"),
Property.text("category"))
.vectorConfig(VectorConfig.text2vecTransformers()) // Configure the Contextionary embedding model
);
CollectionHandle<Map<String, Object>> questions = client.collections.use(collectionName);

HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI
.create("https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json"))
.build();
HttpResponse<String> responseHttp = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
String responseBody = responseHttp.body();

ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, String>> data = objectMapper.readValue(responseBody, new TypeReference<>() {
});

// Create a list to hold the objects for insertion
List<Map<String, Object>> questionsToInsert = new ArrayList<>();

// Populate the list with the data
for (Map<String, String> d : data) {
Map<String, Object> properties = new HashMap<>();
properties.put("answer", d.get("Answer"));
properties.put("question", d.get("Question"));
properties.put("category", d.get("Category"));
questionsToInsert.add(properties);
}

// Call insertMany with the list of objects
InsertManyResponse insertResponse = questions.data.insertMany(questionsToInsert.toArray(new Map[0]));

// Check for errors
if (!insertResponse.errors().isEmpty()) {
System.err.println("Errors during insertMany: " + insertResponse.errors());
}

// Perform a vector similarity search
var queryResponse = questions.query.nearText("biology", q -> q.limit(2));

for (var obj : queryResponse.objects()) {
System.out.println(obj.properties());
}

有关更多代码示例,请查看 操作手册和指南 部分。

异步使用

即将推出

发布版本

转到 GitHub 发布页面,以查看 Java 客户端库发布的历史记录和变更日志。

点击此处查看 Weaviate 和相应客户端版本的表格

此表列出了最新的五个 Weaviate 数据库版本和相应的客户端库版本。

Weaviate 数据库
(GitHub)
首次
发布日期
Python
(GitHub)
TypeScript/
JavaScript
(GitHub)
Go
(GitHub)
Java
(GitHub)
1.35.x2025-12-174.19.xN/AN/AN/A
1.34.x2025-11-054.18.x3.10.x5.6.x6.0.0
1.33.x2025-09-254.17.x3.9.x5.5.x5.5.x
1.32.x2025-07-144.16.x3.8.x5.3.x5.4.x
1.31.x2025-05-304.15.x3.6.x5.2.x5.3.x
1.30.x2025-04-034.12.x3.5.x5.1.x5.2.x
1.29.x2025-02-174.11.x3.4.x5.0.x5.1.x
旧版本发布
Weaviate 数据库
(GitHub)
首次
发布日期
Python
(GitHub)
TypeScript/
JavaScript
(GitHub)
Go
(GitHub)
Java
(GitHub)
1.28.x2024-12-114.10.x3.3.x4.16.x5.0.x
1.27.x2024-10-164.9.x3.2.x4.16.x5.0.x
4.9.x
1.26.x2024-07-224.7.x3.1.x4.15.x4.8.x
1.25.x2024-05-104.6.x2.1.x4.13.x4.6.x
1.24.x2024-02-274.5.x2.0.x4.10.x4.4.x
1.23.x2023-12-183.26.x1.5.x4.10.x4.4.x
1.22.x2023-10-273.25.x1.5.x4.10.x4.3.x
1.21.x2023-08-173.22.x1.4.x4.9.x4.2.x
1.20.x2023-07-063.22.x1.1.x4.7.x4.2.x
1.19.x2023-05-043.17.x1.1.x14.7.x4.0.x
1.18.x2023-03-073.13.x2.14.x4.6.x3.6.x
1.17.x2022-12-203.9.x2.14.x4.5.x3.5.x
1.16.x2022-10-313.8.x2.13.x4.4.x3.4.x
1.15.x2022-09-073.6.x2.12.x4.3.x3.3.x
1.14.x2022-07-073.6.x2.11.x4.2.x3.2.x
1.13.x2022-05-033.4.x2.9.x4.0.x2.4.x
1.12.x2022-04-053.4.x2.8.x3.0.x2.3.x
1.11.x2022-03-143.2.x2.7.x2.6.x2.3.x
1.10.x2022-01-273.1.x2.5.x2.4.x2.1.x
1.9.x2021-12-103.1.x2.4.x2.4.x2.1.x
1.8.x2021-11-303.1.x2.4.x2.3.x1.1.x
1.7.x2021-09-013.1.x2.4.x2.3.x1.1.x
1.6.x2021-08-112.4.x2.3.x2.2.x1.0.x
1.5.x2021-07-132.2.x2.1.x2.1.x1.0.x
1.4.x2021-06-092.2.x2.1.x2.1.x1.0.x
1.3.x2021-04-232.2.x2.1.x2.1.x1.0.x
1.2.x2021-03-152.2.x2.0.x1.1.x-
1.1.x2021-02-102.1.x---
1.0.x2021-01-142.0.x---

TypeScript 客户端变更

TypeScript 客户端 于 2023-03-17 替换了 JavaScript 客户端

代码示例和更多资源

可以在 Weaviate 文档中找到有关各种操作和功能的用法信息。



Weaviate API 参考页面中的 搜索REST 也可能是很好的起点。

问题和反馈

如果您有任何问题或反馈,请在 用户论坛 中告诉我们。