qdrant by giuseppe-trisciuoglio/developer-kit
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill qdrantQdrant 是一个面向语义搜索和相似性检索的 AI 原生向量数据库。本技能提供了将 Qdrant 与 Java 应用程序集成的模式,重点关注 Spring Boot 集成和 LangChain4j 框架支持。为 RAG 系统、推荐引擎和语义搜索应用程序提供高效的向量搜索能力。
在实现以下功能时使用此技能:
按照以下步骤将 Qdrant 集成到您的 Java 应用程序中:
使用 Docker 启动 Qdrant 以进行本地开发:
docker run -p 6333:6333 -p 6334:6334 \
-v "$(pwd)/qdrant_storage:/qdrant/storage:z" \
qdrant/qdrant
在您的构建配置中包含 Qdrant 客户端依赖项:
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.15.0</version>
</dependency>
创建并配置 Qdrant 客户端:
QdrantClient client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost").build()
);
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用适当的维度设置向量集合:
client.createCollectionAsync("search-collection",
VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(384)
.build()
).get();
插入和搜索向量:
// Upsert vectors
List<PointStruct> points = List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.05f, 0.61f, 0.76f, 0.74f))
.build()
);
client.upsertAsync("search-collection", points).get();
// Search vectors
List<ScoredPoint> results = client.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("search-collection")
.setLimit(5)
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
.build()
).get();
在 RAG 应用程序中使用 LangChain4j 的 QdrantEmbeddingStore:
EmbeddingStore<TextSegment> embeddingStore = QdrantEmbeddingStore.builder()
.collectionName("rag-collection")
.host("localhost")
.port(6334)
.build();
要开始集成,首先部署一个 Qdrant 实例。
# Pull the latest Qdrant image
docker pull qdrant/qdrant
# Run the Qdrant container
docker run -p 6333:6333 -p 6334:6334 \
-v "$(pwd)/qdrant_storage:/qdrant/storage:z" \
qdrant/qdrant
通过以下方式访问 Qdrant:
http://localhost:6333http://localhost:6334 (Java 客户端使用)将依赖项添加到您的构建配置中,并初始化客户端以进行编程访问。
Maven:
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.15.0</version>
</dependency>
Gradle:
implementation 'io.qdrant:client:1.15.0'
创建并配置 Qdrant 客户端以供应用程序使用:
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
// Basic local connection
QdrantClient client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost").build());
// Secure connection with API key
QdrantClient secureClient = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, false)
.withApiKey("YOUR_API_KEY")
.build());
// Managed connection with TLS
QdrantClient tlsClient = new QdrantClient(
QdrantGrpcClient.newBuilder(channel)
.withApiKey("YOUR_API_KEY")
.build());
使用适当的距离度量和维度创建和配置向量集合。
import io.qdrant.client.grpc.Collections.Distance;
import io.qdrant.client.grpc.Collections.VectorParams;
import java.util.concurrent.ExecutionException;
// Create a collection with cosine distance
client.createCollectionAsync("search-collection",
VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(384)
.build()).get();
// Create collection with configuration
client.createCollectionAsync("recommendation-engine",
VectorParams.newBuilder()
.setDistance(Distance.Euclidean)
.setSize(512)
.build()).get();
执行常见的向量操作,包括插入、搜索和过滤。
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
import java.util.Map;
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.ValueFactory.value;
import static io.qdrant.client.VectorsFactory.vectors;
// Batch upsert vector points
List<PointStruct> points = List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.05f, 0.61f, 0.76f, 0.74f))
.putAllPayload(Map.of(
"title", value("Spring Boot Documentation"),
"content", value("Spring Boot framework documentation")
))
.build(),
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.19f, 0.81f, 0.75f, 0.11f))
.putAllPayload(Map.of(
"title", value("Qdrant Vector Database"),
"content", value("Vector database for AI applications")
))
.build()
);
client.upsertAsync("search-collection", points).get();
import io.qdrant.client.grpc.Points.QueryPoints;
import io.qdrant.client.grpc.Points.ScoredPoint;
import static io.qdrant.client.QueryFactory.nearest;
import java.util.List;
// Basic similarity search
List<ScoredPoint> results = client.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("search-collection")
.setLimit(5)
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
.build()
).get();
// Search with filters
List<ScoredPoint> filteredResults = client.searchAsync(
SearchPoints.newBuilder()
.setCollectionName("search-collection")
.addAllVector(List.of(0.6235f, 0.123f, 0.532f, 0.123f))
.setFilter(Filter.newBuilder()
.addMust(range("rand_number",
Range.newBuilder().setGte(3).build()))
.build())
.setLimit(5)
.build()).get();
使用依赖注入和适当的配置将 Qdrant 与 Spring Boot 集成。
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QdrantConfig {
@Value("${qdrant.host:localhost}")
private String host;
@Value("${qdrant.port:6334}")
private int port;
@Value("${qdrant.api-key:}")
private String apiKey;
@Bean
public QdrantClient qdrantClient() {
QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder(host, port, false)
.withApiKey(apiKey)
.build();
return new QdrantClient(grpcClient);
}
}
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.ExecutionException;
@Service
public class VectorSearchService {
private final QdrantClient qdrantClient;
public VectorSearchService(QdrantClient qdrantClient) {
this.qdrantClient = qdrantClient;
}
public List<ScoredPoint> search(String collectionName, List<Float> queryVector) {
try {
return qdrantClient.queryAsync(
QueryPoints.newBuilder()
.setCollectionName(collectionName)
.setLimit(5)
.setQuery(nearest(queryVector))
.build()
).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Qdrant search failed", e);
}
}
public void upsertPoints(String collectionName, List<PointStruct> points) {
try {
qdrantClient.upsertAsync(collectionName, points).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Qdrant upsert failed", e);
}
}
}
利用 LangChain4j 实现高级向量存储抽象和 RAG 实现。
Maven:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-qdrant</artifactId>
<version>1.7.0</version>
</dependency>
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.embedding.EmbeddingModel;
import dev.langchain4j.embedding.allminilml6v2.AllMiniLmL6V2EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Langchain4jConfig {
@Bean
public EmbeddingStore<TextSegment> embeddingStore() {
return QdrantEmbeddingStore.builder()
.collectionName("rag-collection")
.host("localhost")
.port(6334)
.apiKey("YOUR_API_KEY")
.build();
}
@Bean
public EmbeddingModel embeddingModel() {
return new AllMiniLmL6V2EmbeddingModel();
}
@Bean
public EmbeddingStoreIngestor embeddingStoreIngestor(
EmbeddingStore<TextSegment> embeddingStore,
EmbeddingModel embeddingModel) {
return EmbeddingStoreIngestor.builder()
.embeddingStore(embeddingStore)
.embeddingModel(embeddingModel)
.build();
}
}
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RagService {
private final EmbeddingStoreIngestor ingestor;
public RagService(EmbeddingStoreIngestor ingestor) {
this.ingestor = ingestor;
}
public void ingestDocument(String text) {
TextSegment segment = TextSegment.from(text);
ingestor.ingest(segment);
}
public List<TextSegment> findRelevant(String query) {
EmbeddingStore<TextSegment> embeddingStore = ingestor.getEmbeddingStore();
return embeddingStore.findRelevant(
ingestor.getEmbeddingModel().embed(query).content(),
5,
0.7
).stream()
.map(match -> match.embedded())
.toList();
}
}
// Create simple search endpoint
@RestController
@RequestMapping("/api/search")
public class SearchController {
private final VectorSearchService searchService;
public SearchController(VectorSearchService searchService) {
this.searchService = searchService;
}
@GetMapping
public List<ScoredPoint> search(@RequestParam String query) {
// Convert query to embedding (requires embedding model)
List<Float> queryVector = embeddingModel.embed(query).content().vectorAsList();
return searchService.search("documents", queryVector);
}
}
// Implement collection-based multi-tenancy
public class MultiTenantVectorService {
private final QdrantClient client;
public void upsertForTenant(String tenantId, List<PointStruct> points) {
String collectionName = "tenant_" + tenantId + "_documents";
client.upsertAsync(collectionName, points).get();
}
}
// Combine vector similarity with metadata filtering
public List<ScoredPoint> hybridSearch(String collectionName, List<Float> queryVector,
String category, Date dateRange) {
Filter filter = Filter.newBuilder()
.addMust(range("created_at",
Range.newBuilder().setGte(dateRange.getTime()).build()))
.addMust(exactMatch("category", category))
.build();
return client.searchAsync(
SearchPoints.newBuilder()
.setCollectionName(collectionName)
.addAllVector(queryVector)
.setFilter(filter)
.build()
).get();
}
有关全面的技术细节和高级模式,请参阅:
每周安装次数
303
代码仓库
GitHub 星标数
173
首次出现
2026年2月9日
安全审计
安装于
claude-code244
opencode240
gemini-cli238
codex235
cursor231
github-copilot224
Qdrant is an AI-native vector database for semantic search and similarity retrieval. This skill provides patterns for integrating Qdrant with Java applications, focusing on Spring Boot integration and LangChain4j framework support. Enable efficient vector search capabilities for RAG systems, recommendation engines, and semantic search applications.
Use this skill when implementing:
Follow these steps to integrate Qdrant with your Java application:
Start Qdrant using Docker for local development:
docker run -p 6333:6333 -p 6334:6334 \
-v "$(pwd)/qdrant_storage:/qdrant/storage:z" \
qdrant/qdrant
Include Qdrant client dependencies in your build configuration:
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.15.0</version>
</dependency>
Create and configure the Qdrant client:
QdrantClient client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost").build()
);
Set up a vector collection with appropriate dimensions:
client.createCollectionAsync("search-collection",
VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(384)
.build()
).get();
Upsert and search vectors:
// Upsert vectors
List<PointStruct> points = List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.05f, 0.61f, 0.76f, 0.74f))
.build()
);
client.upsertAsync("search-collection", points).get();
// Search vectors
List<ScoredPoint> results = client.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("search-collection")
.setLimit(5)
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
.build()
).get();
Use LangChain4j's QdrantEmbeddingStore for RAG applications:
EmbeddingStore<TextSegment> embeddingStore = QdrantEmbeddingStore.builder()
.collectionName("rag-collection")
.host("localhost")
.port(6334)
.build();
To begin integration, first deploy a Qdrant instance.
# Pull the latest Qdrant image
docker pull qdrant/qdrant
# Run the Qdrant container
docker run -p 6333:6333 -p 6334:6334 \
-v "$(pwd)/qdrant_storage:/qdrant/storage:z" \
qdrant/qdrant
Access Qdrant via:
http://localhost:6333http://localhost:6334 (used by Java client)Add dependencies to your build configuration and initialize the client for programmatic access.
Maven:
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
<version>1.15.0</version>
</dependency>
Gradle:
implementation 'io.qdrant:client:1.15.0'
Create and configure the Qdrant client for application use:
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
// Basic local connection
QdrantClient client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost").build());
// Secure connection with API key
QdrantClient secureClient = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, false)
.withApiKey("YOUR_API_KEY")
.build());
// Managed connection with TLS
QdrantClient tlsClient = new QdrantClient(
QdrantGrpcClient.newBuilder(channel)
.withApiKey("YOUR_API_KEY")
.build());
Create and configure vector collections with appropriate distance metrics and dimensions.
import io.qdrant.client.grpc.Collections.Distance;
import io.qdrant.client.grpc.Collections.VectorParams;
import java.util.concurrent.ExecutionException;
// Create a collection with cosine distance
client.createCollectionAsync("search-collection",
VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(384)
.build()).get();
// Create collection with configuration
client.createCollectionAsync("recommendation-engine",
VectorParams.newBuilder()
.setDistance(Distance.Euclidean)
.setSize(512)
.build()).get();
Perform common vector operations including upsert, search, and filtering.
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
import java.util.Map;
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.ValueFactory.value;
import static io.qdrant.client.VectorsFactory.vectors;
// Batch upsert vector points
List<PointStruct> points = List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.05f, 0.61f, 0.76f, 0.74f))
.putAllPayload(Map.of(
"title", value("Spring Boot Documentation"),
"content", value("Spring Boot framework documentation")
))
.build(),
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.19f, 0.81f, 0.75f, 0.11f))
.putAllPayload(Map.of(
"title", value("Qdrant Vector Database"),
"content", value("Vector database for AI applications")
))
.build()
);
client.upsertAsync("search-collection", points).get();
import io.qdrant.client.grpc.Points.QueryPoints;
import io.qdrant.client.grpc.Points.ScoredPoint;
import static io.qdrant.client.QueryFactory.nearest;
import java.util.List;
// Basic similarity search
List<ScoredPoint> results = client.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("search-collection")
.setLimit(5)
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
.build()
).get();
// Search with filters
List<ScoredPoint> filteredResults = client.searchAsync(
SearchPoints.newBuilder()
.setCollectionName("search-collection")
.addAllVector(List.of(0.6235f, 0.123f, 0.532f, 0.123f))
.setFilter(Filter.newBuilder()
.addMust(range("rand_number",
Range.newBuilder().setGte(3).build()))
.build())
.setLimit(5)
.build()).get();
Integrate Qdrant with Spring Boot using dependency injection and proper configuration.
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QdrantConfig {
@Value("${qdrant.host:localhost}")
private String host;
@Value("${qdrant.port:6334}")
private int port;
@Value("${qdrant.api-key:}")
private String apiKey;
@Bean
public QdrantClient qdrantClient() {
QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder(host, port, false)
.withApiKey(apiKey)
.build();
return new QdrantClient(grpcClient);
}
}
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.ExecutionException;
@Service
public class VectorSearchService {
private final QdrantClient qdrantClient;
public VectorSearchService(QdrantClient qdrantClient) {
this.qdrantClient = qdrantClient;
}
public List<ScoredPoint> search(String collectionName, List<Float> queryVector) {
try {
return qdrantClient.queryAsync(
QueryPoints.newBuilder()
.setCollectionName(collectionName)
.setLimit(5)
.setQuery(nearest(queryVector))
.build()
).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Qdrant search failed", e);
}
}
public void upsertPoints(String collectionName, List<PointStruct> points) {
try {
qdrantClient.upsertAsync(collectionName, points).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Qdrant upsert failed", e);
}
}
}
Leverage LangChain4j for high-level vector store abstractions and RAG implementations.
Maven:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-qdrant</artifactId>
<version>1.7.0</version>
</dependency>
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.embedding.EmbeddingModel;
import dev.langchain4j.embedding.allminilml6v2.AllMiniLmL6V2EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Langchain4jConfig {
@Bean
public EmbeddingStore<TextSegment> embeddingStore() {
return QdrantEmbeddingStore.builder()
.collectionName("rag-collection")
.host("localhost")
.port(6334)
.apiKey("YOUR_API_KEY")
.build();
}
@Bean
public EmbeddingModel embeddingModel() {
return new AllMiniLmL6V2EmbeddingModel();
}
@Bean
public EmbeddingStoreIngestor embeddingStoreIngestor(
EmbeddingStore<TextSegment> embeddingStore,
EmbeddingModel embeddingModel) {
return EmbeddingStoreIngestor.builder()
.embeddingStore(embeddingStore)
.embeddingModel(embeddingModel)
.build();
}
}
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RagService {
private final EmbeddingStoreIngestor ingestor;
public RagService(EmbeddingStoreIngestor ingestor) {
this.ingestor = ingestor;
}
public void ingestDocument(String text) {
TextSegment segment = TextSegment.from(text);
ingestor.ingest(segment);
}
public List<TextSegment> findRelevant(String query) {
EmbeddingStore<TextSegment> embeddingStore = ingestor.getEmbeddingStore();
return embeddingStore.findRelevant(
ingestor.getEmbeddingModel().embed(query).content(),
5,
0.7
).stream()
.map(match -> match.embedded())
.toList();
}
}
// Create simple search endpoint
@RestController
@RequestMapping("/api/search")
public class SearchController {
private final VectorSearchService searchService;
public SearchController(VectorSearchService searchService) {
this.searchService = searchService;
}
@GetMapping
public List<ScoredPoint> search(@RequestParam String query) {
// Convert query to embedding (requires embedding model)
List<Float> queryVector = embeddingModel.embed(query).content().vectorAsList();
return searchService.search("documents", queryVector);
}
}
// Implement collection-based multi-tenancy
public class MultiTenantVectorService {
private final QdrantClient client;
public void upsertForTenant(String tenantId, List<PointStruct> points) {
String collectionName = "tenant_" + tenantId + "_documents";
client.upsertAsync(collectionName, points).get();
}
}
// Combine vector similarity with metadata filtering
public List<ScoredPoint> hybridSearch(String collectionName, List<Float> queryVector,
String category, Date dateRange) {
Filter filter = Filter.newBuilder()
.addMust(range("created_at",
Range.newBuilder().setGte(dateRange.getTime()).build()))
.addMust(exactMatch("category", category))
.build();
return client.searchAsync(
SearchPoints.newBuilder()
.setCollectionName(collectionName)
.addAllVector(queryVector)
.setFilter(filter)
.build()
).get();
}
For comprehensive technical details and advanced patterns, see:
Weekly Installs
303
Repository
GitHub Stars
173
First Seen
Feb 9, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code244
opencode240
gemini-cli238
codex235
cursor231
github-copilot224
超能力技能使用指南:AI助手技能调用优先级与工作流程详解
41,800 周安装