Spring AI
春季人工智能 是一个 Java 框架,提供了 春季友好 的 API 和抽象,用于开发 AI 应用程序。
Qdrant 可作为支持的向量数据库,用于您的 Spring AI 项目中。
安装
你可以找到Spring AI的安装说明这里。
添加Qdrant启动器包。
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-qdrant-store-spring-boot-starter</artifactId>
</dependency>
用法
使用Spring Boot的application.properties配置Qdrant。
spring.ai.vectorstore.qdrant.host=<host of your qdrant instance>
spring.ai.vectorstore.qdrant.port=<the GRPC port of your qdrant instance>
spring.ai.vectorstore.qdrant.api-key=<your api key>
spring.ai.vectorstore.qdrant.collection-name=<The name of the collection to use in Qdrant>
了解更多关于这些选项的信息,请参阅配置参考。
或者你可以使用QdrantVectorStoreConfig选项来设置Qdrant向量存储。
@Bean
public QdrantVectorStoreConfig qdrantVectorStoreConfig() {
return QdrantVectorStoreConfig.builder()
.withHost("<QDRANT_HOSTNAME>")
.withPort(<QDRANT_GRPC_PORT>)
.withCollectionName("<QDRANT_COLLECTION_NAME>")
.withApiKey("<QDRANT_API_KEY>")
.build();
}
使用配置和任何支持的Spring AI嵌入提供者构建向量存储。
@Bean
public VectorStore vectorStore(QdrantVectorStoreConfig config, EmbeddingClient embeddingClient) {
return new QdrantVectorStore(config, embeddingClient);
}
您现在可以在Spring AI API中使用由Qdrant支持的VectorStore实例作为向量存储。
