$npx -y skills add giuseppe-trisciuoglio/developer-kit --skill qdrantProvides Qdrant vector database integration patterns with LangChain4j. Handles embedding storage, similarity search, and vector management for Java applications. Use when implementing vector-based retrieval for RAG systems, semantic search, or recommendation engines.
| 1 | # Qdrant Vector Database Integration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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 and LangChain4j integration. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Semantic search or recommendation systems in Spring Boot applications |
| 10 | - RAG pipelines with Java and LangChain4j |
| 11 | - Vector database integration for AI/ML applications |
| 12 | - High-performance similarity search with filtered queries |
| 13 | |
| 14 | ## Instructions |
| 15 | |
| 16 | ### 1. Deploy Qdrant with Docker |
| 17 | |
| 18 | ```bash |
| 19 | docker run -p 6333:6333 -p 6334:6334 \ |
| 20 | -v "$(pwd)/qdrant_storage:/qdrant/storage:z" \ |
| 21 | qdrant/qdrant |
| 22 | ``` |
| 23 | |
| 24 | Access: REST API at `http://localhost:6333`, gRPC at `http://localhost:6334`. |
| 25 | |
| 26 | ### 2. Add Dependencies |
| 27 | |
| 28 | **Maven:** |
| 29 | ```xml |
| 30 | <dependency> |
| 31 | <groupId>io.qdrant</groupId> |
| 32 | <artifactId>client</artifactId> |
| 33 | <version>1.15.0</version> |
| 34 | </dependency> |
| 35 | ``` |
| 36 | |
| 37 | **Gradle:** |
| 38 | ```gradle |
| 39 | implementation 'io.qdrant:client:1.15.0' |
| 40 | ``` |
| 41 | |
| 42 | ### 3. Initialize Client |
| 43 | |
| 44 | ```java |
| 45 | QdrantClient client = new QdrantClient( |
| 46 | QdrantGrpcClient.newBuilder("localhost").build()); |
| 47 | ``` |
| 48 | |
| 49 | For production with API key: |
| 50 | ```java |
| 51 | QdrantClient client = new QdrantClient( |
| 52 | QdrantGrpcClient.newBuilder("localhost", 6334, false) |
| 53 | .withApiKey("YOUR_API_KEY") |
| 54 | .build()); |
| 55 | ``` |
| 56 | |
| 57 | ### 4. Create Collection |
| 58 | |
| 59 | ```java |
| 60 | client.createCollectionAsync("search-collection", |
| 61 | VectorParams.newBuilder() |
| 62 | .setDistance(Distance.Cosine) |
| 63 | .setSize(384) |
| 64 | .build() |
| 65 | ).get(); |
| 66 | ``` |
| 67 | |
| 68 | **Validation:** Verify the collection was created by checking `client.getCollectionAsync("search-collection").get()`. |
| 69 | |
| 70 | ### 5. Upsert Vectors |
| 71 | |
| 72 | ```java |
| 73 | List<PointStruct> points = List.of( |
| 74 | PointStruct.newBuilder() |
| 75 | .setId(id(1)) |
| 76 | .setVectors(vectors(0.05f, 0.61f, 0.76f, 0.74f)) |
| 77 | .putAllPayload(Map.of("title", value("Spring Boot Documentation"))) |
| 78 | .build() |
| 79 | ); |
| 80 | client.upsertAsync("search-collection", points).get(); |
| 81 | ``` |
| 82 | |
| 83 | **Validation:** Check that `client.upsertAsync(...).get()` completes without throwing. |
| 84 | |
| 85 | ### 6. Search Vectors |
| 86 | |
| 87 | ```java |
| 88 | List<ScoredPoint> results = client.queryAsync( |
| 89 | QueryPoints.newBuilder() |
| 90 | .setCollectionName("search-collection") |
| 91 | .setLimit(5) |
| 92 | .setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f)) |
| 93 | .build() |
| 94 | ).get(); |
| 95 | ``` |
| 96 | |
| 97 | Filtered search: |
| 98 | ```java |
| 99 | List<ScoredPoint> results = client.searchAsync( |
| 100 | SearchPoints.newBuilder() |
| 101 | .setCollectionName("search-collection") |
| 102 | .addAllVector(List.of(0.62f, 0.12f, 0.53f, 0.12f)) |
| 103 | .setFilter(Filter.newBuilder() |
| 104 | .addMust(range("category", Range.newBuilder().setEq("docs").build())) |
| 105 | .build()) |
| 106 | .setLimit(5) |
| 107 | .build()).get(); |
| 108 | ``` |
| 109 | |
| 110 | ## LangChain4j Integration |
| 111 | |
| 112 | For RAG pipelines, use LangChain4j's high-level abstractions: |
| 113 | |
| 114 | ```java |
| 115 | EmbeddingStore<TextSegment> embeddingStore = QdrantEmbeddingStore.builder() |
| 116 | .collectionName("rag-collection") |
| 117 | .host("localhost") |
| 118 | .port(6334) |
| 119 | .apiKey("YOUR_API_KEY") |
| 120 | .build(); |
| 121 | ``` |
| 122 | |
| 123 | Spring Boot configuration with LangChain4j: |
| 124 | ```java |
| 125 | @Bean |
| 126 | public EmbeddingStore<TextSegment> embeddingStore() { |
| 127 | return QdrantEmbeddingStore.builder() |
| 128 | .collectionName("rag-collection") |
| 129 | .host(host) |
| 130 | .port(port) |
| 131 | .build(); |
| 132 | } |
| 133 | |
| 134 | @Bean |
| 135 | public EmbeddingModel embeddingModel() { |
| 136 | return new AllMiniLmL6V2EmbeddingModel(); |
| 137 | } |
| 138 | ``` |
| 139 | |
| 140 | ## Spring Boot Integration |
| 141 | |
| 142 | Inject the client via configuration: |
| 143 | |
| 144 | ```java |
| 145 | @Configuration |
| 146 | public class QdrantConfig { |
| 147 | @Value("${qdrant.host:localhost}") |
| 148 | private String host; |
| 149 | |
| 150 | @Value("${qdrant.port:6334}") |
| 151 | private int port; |
| 152 | |
| 153 | @Bean |
| 154 | public QdrantClient qdrantClient() { |
| 155 | return new QdrantClient( |
| 156 | QdrantGrpcClient.newBuilder(host, port, false).build()); |
| 157 | } |
| 158 | } |
| 159 | ``` |
| 160 | |
| 161 | ## Examples |
| 162 | |
| 163 | ### REST Search Endpoint |
| 164 | |
| 165 | ```java |
| 166 | @RestController |
| 167 | @RequestMapping("/api/search") |
| 168 | public class SearchController { |
| 169 | private final VectorSearchService searchService; |
| 170 | |
| 171 | public SearchController(VectorSearchService searchService) { |
| 172 | this.searchService = searchService; |
| 173 | } |
| 174 | |
| 175 | @GetMapping |
| 176 | public List<ScoredPoint> search(@RequestParam String query) { |
| 177 | List<Float> queryVector = embeddingModel.embed(query).content().vectorAsList(); |
| 178 | return searchService.search("documents", queryVector); |
| 179 | } |
| 180 | } |
| 181 | ``` |
| 182 | |
| 183 | ## Best Practices |
| 184 | |
| 185 | - **Distance metric**: Cosine for normalized text embeddings, Euclidean for non-normalized. |
| 186 | - **Batch upserts**: Use batch operations over individual point insertions. |
| 187 | - **Connection pooling**: Configure connection pooling for high-throughput production workloads. |
| 188 | - **Error handling**: W |