File tree Expand file tree Collapse file tree 7 files changed +168
-0
lines changed
src/main/java/io/qdrant/example Expand file tree Collapse file tree 7 files changed +168
-0
lines changed Original file line number Diff line number Diff line change 1+ .git
2+ .gradle
3+ build /
4+ ! build /libs /* .jar
5+ * .md
6+ gradlew
7+ gradlew.bat
8+ gradle /
Original file line number Diff line number Diff line change 1+ # Use OpenJDK 11 as base image
2+ FROM openjdk:11-jdk-slim AS build
3+
4+ # Set working directory
5+ WORKDIR /app
6+
7+ # Install Gradle
8+ RUN apt-get update && \
9+ apt-get install -y wget unzip && \
10+ wget https://services.gradle.org/distributions/gradle-8.4-bin.zip && \
11+ unzip gradle-8.4-bin.zip && \
12+ rm gradle-8.4-bin.zip && \
13+ mv gradle-8.4 /opt/gradle && \
14+ ln -s /opt/gradle/bin/gradle /usr/local/bin/gradle && \
15+ apt-get remove -y wget unzip && \
16+ apt-get autoremove -y && \
17+ apt-get clean && \
18+ rm -rf /var/lib/apt/lists/*
19+
20+ # Copy source code and build files
21+ COPY . .
22+
23+ # Build the application fat jar
24+ RUN gradle --no-daemon clean shadowJar
25+
26+ # Create a runtime image
27+ FROM openjdk:11-jre-slim
28+
29+ WORKDIR /app
30+
31+ # Copy the built JAR from the build stage (versioned shaded jar)
32+ COPY --from=build /app/build/libs/app-*-all.jar /app/app.jar
33+
34+ # Set the entrypoint
35+ ENTRYPOINT ["java" , "-jar" , "app.jar" ]
Original file line number Diff line number Diff line change 1+ # Simple Qdrant Client Example
2+
3+ This is a simple Java application that demonstrates how to interact with a Qdrant vector database server using the official Qdrant Java client.
4+
5+ ## Prerequisites
6+
7+ - Docker installed on your system
8+
9+ ## Quick Start
10+
11+ ### 1. Start Qdrant
12+
13+ First, make sure Qdrant is running. You can start it with Docker:
14+
15+ ``` bash
16+ docker run --rm -it -p 6334:6334 -p 6333:6333 qdrant/qdrant
17+ ```
18+
19+ ### 2. Building and Running
20+
21+ ``` bash
22+ bash -x build-and-run.sh
23+ ```
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ docker build -t qdrant-simple-example .
4+
5+ docker run --rm -it --network host qdrant-simple-example
Original file line number Diff line number Diff line change 1+ plugins {
2+ id ' java'
3+ id ' application'
4+ id ' com.github.johnrengelman.shadow' version ' 8.1.1'
5+ }
6+
7+ group = ' io.qdrant.example'
8+ version = ' 1.0.0'
9+
10+ repositories {
11+ mavenCentral()
12+ }
13+
14+ dependencies {
15+ // Qdrant Java client
16+ implementation ' io.qdrant:client:1.15.0'
17+
18+ // gRPC dependencies - use the same version as Qdrant client
19+ implementation ' io.grpc:grpc-netty-shaded:1.65.1'
20+ implementation ' io.grpc:grpc-protobuf:1.65.1'
21+ implementation ' io.grpc:grpc-stub:1.65.1'
22+ implementation ' io.grpc:grpc-services:1.65.1'
23+
24+ // Protobuf runtime
25+ implementation ' com.google.protobuf:protobuf-java:3.25.4'
26+
27+ // Logging
28+ implementation ' org.slf4j:slf4j-simple:2.0.14'
29+ }
30+
31+ application {
32+ mainClass = ' io.qdrant.example.QdrantExample'
33+ }
34+
35+ java {
36+ sourceCompatibility = JavaVersion . VERSION_11
37+ targetCompatibility = JavaVersion . VERSION_11
38+ }
39+
40+ // Create a proper fat jar and merge service descriptor files (required by gRPC)
41+ shadowJar {
42+ mergeServiceFiles()
43+ archiveBaseName. set(' app' )
44+ archiveClassifier. set(' all' )
45+ }
46+
47+ // Keep the plain jar minimal (no dependency unpacking)
48+ jar {
49+ manifest {
50+ attributes ' Main-Class' : ' io.qdrant.example.QdrantExample'
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ org.gradle.jvmargs =-Xmx2048m -Dfile.encoding =UTF-8
2+ org.gradle.parallel =true
3+ org.gradle.caching =true
Original file line number Diff line number Diff line change 1+ package io .qdrant .example ;
2+
3+ import io .qdrant .client .QdrantClient ;
4+ import io .qdrant .client .QdrantGrpcClient ;
5+ import io .qdrant .client .grpc .Collections .VectorParams ;
6+ import io .qdrant .client .grpc .Collections .Distance ;
7+ import java .util .List ;
8+
9+ public class QdrantExample {
10+ public static void main (String [] args ) {
11+ try {
12+ QdrantClient client = new QdrantClient (QdrantGrpcClient .newBuilder ("localhost" , 6334 , false )
13+ .build ());
14+
15+ // Create a simple collection
16+ String collectionName = "example_collection" ;
17+
18+ if (!client .collectionExistsAsync (collectionName ).get ()) {
19+ client .createCollectionAsync (
20+ collectionName ,
21+ VectorParams .newBuilder ()
22+ .setDistance (Distance .Cosine )
23+ .setSize (128 )
24+ .build ()
25+ ).get ();
26+ }
27+
28+ List <String > collections = client .listCollectionsAsync ().get ();
29+
30+ for (String collection : collections ) {
31+ System .out .println ("- " + collection );
32+ }
33+
34+ client .close ();
35+
36+ } catch (Exception e ) {
37+ System .err .println ("Error occurred: " + e .getMessage ());
38+ e .printStackTrace ();
39+ System .exit (1 );
40+ }
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments