Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions example/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.gradle
build/
!build/libs/*.jar
*.md
gradlew
gradlew.bat
gradle/
35 changes: 35 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use OpenJDK 11 as base image
FROM openjdk:11-jdk-slim AS build

# Set working directory
WORKDIR /app

# Install Gradle
RUN apt-get update && \
apt-get install -y wget unzip && \
wget https://services.gradle.org/distributions/gradle-8.4-bin.zip && \
unzip gradle-8.4-bin.zip && \
rm gradle-8.4-bin.zip && \
mv gradle-8.4 /opt/gradle && \
ln -s /opt/gradle/bin/gradle /usr/local/bin/gradle && \
apt-get remove -y wget unzip && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy source code and build files
COPY . .

# Build the application fat jar
RUN gradle --no-daemon clean shadowJar

# Create a runtime image
FROM openjdk:11-jre-slim

WORKDIR /app

# Copy the built JAR from the build stage (versioned shaded jar)
COPY --from=build /app/build/libs/app-*-all.jar /app/app.jar

# Set the entrypoint
ENTRYPOINT ["java", "-jar", "app.jar"]
23 changes: 23 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Simple Qdrant Client Example

This is a simple Java application that demonstrates how to interact with a Qdrant vector database server using the official Qdrant Java client.

## Prerequisites

- Docker installed on your system

## Quick Start

### 1. Start Qdrant

First, make sure Qdrant is running. You can start it with Docker:

```bash
docker run --rm -it -p 6334:6334 -p 6333:6333 qdrant/qdrant
```

### 2. Building and Running

```bash
bash -x build-and-run.sh
```
5 changes: 5 additions & 0 deletions example/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

docker build -t qdrant-simple-example .

docker run --rm -it --network host qdrant-simple-example
52 changes: 52 additions & 0 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group = 'io.qdrant.example'
version = '1.0.0'

repositories {
mavenCentral()
}

dependencies {
// Qdrant Java client
implementation 'io.qdrant:client:1.15.0'

// gRPC dependencies - use the same version as Qdrant client
implementation 'io.grpc:grpc-netty-shaded:1.65.1'
implementation 'io.grpc:grpc-protobuf:1.65.1'
implementation 'io.grpc:grpc-stub:1.65.1'
implementation 'io.grpc:grpc-services:1.65.1'

// Protobuf runtime
implementation 'com.google.protobuf:protobuf-java:3.25.4'

// Logging
implementation 'org.slf4j:slf4j-simple:2.0.14'
}

application {
mainClass = 'io.qdrant.example.QdrantExample'
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

// Create a proper fat jar and merge service descriptor files (required by gRPC)
shadowJar {
mergeServiceFiles()
archiveBaseName.set('app')
archiveClassifier.set('all')
}

// Keep the plain jar minimal (no dependency unpacking)
jar {
manifest {
attributes 'Main-Class': 'io.qdrant.example.QdrantExample'
}
}
3 changes: 3 additions & 0 deletions example/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=true
42 changes: 42 additions & 0 deletions example/src/main/java/io/qdrant/example/QdrantExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.qdrant.example;

import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Collections.VectorParams;
import io.qdrant.client.grpc.Collections.Distance;
import java.util.List;

public class QdrantExample {
public static void main(String[] args) {
try {
QdrantClient client = new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false)
.build());

// Create a simple collection
String collectionName = "example_collection";

if (!client.collectionExistsAsync(collectionName).get()) {
client.createCollectionAsync(
collectionName,
VectorParams.newBuilder()
.setDistance(Distance.Cosine)
.setSize(128)
.build()
).get();
}

List<String> collections = client.listCollectionsAsync().get();

for (String collection : collections) {
System.out.println("- " + collection);
}

client.close();

} catch (Exception e) {
System.err.println("Error occurred: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
}
Loading