### Start Qdrant with Docker Source: https://github.com/qdrant/java-client/blob/master/example/README.md Starts a Qdrant instance using Docker. Ensure Docker is installed and running. ```bash docker run --rm -it -p 6334:6334 -p 6333:6333 qdrant/qdrant ``` -------------------------------- ### Create Recommend Query Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Creates a recommendation query based on positive and negative examples. ```java public static Query recommend(RecommendInput input) ``` -------------------------------- ### Build and Run Java Application Source: https://github.com/qdrant/java-client/blob/master/example/README.md Executes a build and run script for the Java Qdrant client example. Assumes the script is available in the project. ```bash bash -x build-and-run.sh ``` -------------------------------- ### Minimal Local Qdrant Setup Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Connects to a local Qdrant instance running on default port 6334 without TLS. Suitable for development environments. ```java QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("localhost") .build() ); ``` -------------------------------- ### Create Discover Query Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Creates a discovery query to explore items similar to one example but not like another. ```java public static Query discover(DiscoverInput input) ``` -------------------------------- ### Import Static Declarations Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Provides examples of using 'import static' for cleaner code when frequently using factory methods. ```java import static io.qdrant.client.ValueFactory.value; import static io.qdrant.client.PointIdFactory.id; import static io.qdrant.client.VectorFactory.vector; ``` -------------------------------- ### Qdrant Client Version Compatibility Example Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Illustrates the compatible range of Qdrant server versions for a specific client version. Client v1.18.1 is compatible with server versions from v1.17.x through v1.19.x. ```text Example: Client v1.18.1 works with server v1.17.x through v1.19.x ``` -------------------------------- ### Production Remote Qdrant Cloud Setup Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Connects to a remote Qdrant Cloud instance using TLS, API key authentication, and a 30-second timeout. Ensure to replace placeholders with your actual instance details and API key. ```java QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("your-qdrant-instance.qdrant.io") .withApiKey("your-api-key") .withTimeout(Duration.ofSeconds(30)) .build() ); ``` -------------------------------- ### QdrantGrpcClient Configuration Source: https://github.com/qdrant/java-client/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Configuration details for the gRPC client, including static builder methods, builder configuration methods, and public service stub methods. Examples for authentication and TLS configuration are provided. ```APIDOC ## QdrantGrpcClient Configuration ### Description This section covers the configuration and usage of the gRPC-based client for Qdrant. It outlines the methods available for building and configuring the client, as well as interacting with the Qdrant service via gRPC. ### Builder Methods - **Static Builder Methods**: 7 static methods are available for initiating the client builder. - **Builder Configuration Methods**: 4 methods allow for detailed configuration of the client, including authentication and TLS settings. ### Service Stub Methods - **Public Service Stub Methods**: 4 public methods are exposed for direct interaction with Qdrant's gRPC services. ### Examples Includes examples for setting up authentication (API key, custom headers, call credentials, metadata credentials) and configuring TLS connections. ``` -------------------------------- ### Selective Retrieval Example Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Demonstrates retrieving points with specific payload fields and vectors, excluding others, and setting a timeout. ```java List points = client.retrieveAsync( "products", List.of(PointIdFactory.id(1), PointIdFactory.id(2)), WithPayloadSelectorFactory.include("name", "price"), WithVectorsSelectorFactory.exclude("raw_vector"), null, Duration.ofSeconds(30) ).get(); ``` -------------------------------- ### Selective Retrieval Example Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Demonstrates how to perform a selective retrieval of points, specifying which payload fields and vectors to include or exclude. ```APIDOC ### Selective Retrieval ```java List points = client.retrieveAsync( "products", List.of(PointIdFactory.id(1), PointIdFactory.id(2)), WithPayloadSelectorFactory.include("name", "price"), WithVectorsSelectorFactory.exclude("raw_vector"), null, Duration.ofSeconds(30) ).get(); ``` ``` -------------------------------- ### Handle Asynchronous Operation Results with Blocking Get Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Illustrates how to synchronously retrieve the result of an asynchronous operation using .get() and handle potential ExecutionExceptions, including Qdrant-specific errors. ```java try { client.createCollectionAsync("my_collection", vectorParams).get(); } catch (ExecutionException e) { if (e.getCause() instanceof QdrantException) { // Handle Qdrant error } } ``` -------------------------------- ### Collection Management Source: https://github.com/qdrant/java-client/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Methods for managing collections within Qdrant, including creation, deletion, retrieval of information, and cluster setup. ```APIDOC ## Collection Management This section covers methods for managing collections in Qdrant. ### Methods - `createCollectionAsync` (6 overloads) - `deleteCollectionAsync` (2 overloads) - `recreateCollectionAsync` (6 overloads) - `getCollectionInfoAsync` (2 overloads) - `getCollectionClusterInfoAsync` (2 overloads) - `listCollectionsAsync` (2 overloads) - `updateCollectionAsync` (2 overloads) - `updateCollectionClusterSetupAsync` (2 overloads) - `collectionExistsAsync` (2 overloads) ``` -------------------------------- ### Payload Map Example Source: https://github.com/qdrant/java-client/blob/master/_autodocs/types.md Represents a payload as a Map, used for storing arbitrary data with points. ```java Map payload = Map.of( "name", ValueFactory.value("John"), "age", ValueFactory.value(30), "tags", ValueFactory.list(List.of(ValueFactory.value("dev"))) ); ``` -------------------------------- ### Custom Headers for Tenant and Request ID Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Example of setting custom headers, including a tenant identifier and a unique request ID generated using UUID. This is useful for multi-tenancy or request tracing. ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost") .withHeaders(Map.of( "X-Tenant-ID", "my-org", "X-Request-ID", UUID.randomUUID().toString() )) .build(); ``` -------------------------------- ### Insert Vectors into a Collection Source: https://github.com/qdrant/java-client/blob/master/README.md Insert multiple points with vectors and payloads into a Qdrant collection. This example demonstrates using convenience methods for point IDs, values, and vectors. ```java // import static convenience methods import static io.qdrant.client.PointIdFactory.id; import static io.qdrant.client.ValueFactory.value; import static io.qdrant.client.VectorsFactory.vectors; List points = List.of( PointStruct.newBuilder() .setId(id(1)) .setVectors(vectors(0.32f, 0.52f, 0.21f, 0.52f)) .putAllPayload( Map.of( "color", value("red"), "rand_number", value(32))) .build(), PointStruct.newBuilder() .setId(id(2)) .setVectors(vectors(0.42f, 0.52f, 0.67f, 0.632f)) .putAllPayload( Map.of( "color", value("black"), "rand_number", value(53), "extra_field", value(true))) .build()); UpdateResult updateResult = client.upsertAsync("{collection_name}", points).get(); ``` -------------------------------- ### QdrantClient.java API Source: https://github.com/qdrant/java-client/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt The main client API for interacting with Qdrant. It exposes over 159 public methods categorized into 9 groups, with detailed parameter tables, return types, exceptions, and real-world code examples. ```APIDOC ## QdrantClient.java API Reference ### Description This section details the primary Java client interface for interacting with the Qdrant vector database. It provides access to a comprehensive set of methods for managing collections, points, and performing search operations. ### Methods This API includes over 159 public methods organized into 9 distinct categories, covering all core functionalities of the Qdrant service. ### Parameters Detailed parameter tables are provided for all method signatures, specifying types, descriptions, and whether they are required or optional. ### Return Types and Exceptions Information regarding the return types for each method and potential exceptions that may be thrown is documented. ### Code Examples Real-world code examples are included to demonstrate the usage of various methods within the `QdrantClient`. ``` -------------------------------- ### Search with Filtering Conditions Source: https://github.com/qdrant/java-client/blob/master/README.md Execute a vector search with a filter applied to the payload. This example filters points based on a numeric range condition using convenience methods. ```java // import static convenience methods import static io.qdrant.client.ConditionFactory.range; List points = client.searchAsync(SearchPoints.newBuilder() .setCollectionName("{collection_name}") .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(); ``` -------------------------------- ### Get Collection Info Async Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Retrieves detailed information about a collection asynchronously. Use this to get metadata, vector stats, and point count. ```java CollectionInfo info = client.getCollectionInfoAsync("my_collection").get(); System.out.println("Points count: " + info.getPointsCount()); ``` -------------------------------- ### Basic Qdrant Java Client Usage Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Demonstrates creating a client, creating a collection, inserting points, and performing a search. Uses static imports for factory methods. ```java 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 static io.qdrant.client.PointIdFactory.id; import static io.qdrant.client.ValueFactory.value; import static io.qdrant.client.VectorsFactory.vectors; // Create client QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("localhost").build() ); // Create collection client.createCollectionAsync( "my_collection", VectorParams.newBuilder() .setSize(384) .setDistance(Distance.Cosine) .build() ).get(); // Insert points List points = List.of( PointStruct.newBuilder() .setId(id(1)) .setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f)) .putAllPayload(Map.of("name", value("item1"))) .build() ); client.upsertAsync("my_collection", points).get(); // Search List results = client.searchAsync( SearchPoints.newBuilder() .setCollectionName("my_collection") .addAllVector(List.of(0.1f, 0.2f, 0.3f, 0.4f)) .setLimit(10) .build() ).get(); // Clean up client.close(); ``` -------------------------------- ### getCollectionClusterInfoAsync Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Gets cluster configuration and sharding information for a specified collection. ```APIDOC ## getCollectionClusterInfoAsync ### Description Gets cluster configuration and sharding information for a collection. ### Method `getCollectionClusterInfoAsync(String collectionName)` ### Parameters #### Path Parameters - **collectionName** (String) - Required - The name of the collection to get cluster info for. ### Returns `ListenableFuture` ``` -------------------------------- ### updateCollectionClusterSetupAsync Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Updates the cluster setup for a collection, including sharding and replica configuration. ```APIDOC ## updateCollectionClusterSetupAsync ### Description Updates cluster setup for a collection (sharding, replicas). ### Method `updateCollectionClusterSetupAsync(UpdateCollectionClusterSetupRequest updateCollectionClusterSetup)` ### Parameters #### Request Body - **updateCollectionClusterSetup** (UpdateCollectionClusterSetupRequest) - Required - Object containing the cluster setup updates. ### Returns `ListenableFuture` ``` -------------------------------- ### Initialize QdrantClient with QdrantGrpcClient Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Instantiate QdrantClient by providing a configured QdrantGrpcClient. This is the main entry point for all Qdrant operations. ```java QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder("localhost").build(); QdrantClient client = new QdrantClient(grpcClient); ``` -------------------------------- ### Project Directory Structure Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Shows the organization of the Qdrant Java client documentation within the output directory. Key documentation files are listed, including API references and type definitions. ```bash output/ ├── README.md # This file ├── api-reference/ │ ├── QdrantClient.md # Main client API │ ├── QdrantGrpcClient.md # gRPC client │ └── FactoryClasses.md # Factory utilities ├── types.md # Data types and definitions ├── configuration.md # Setup and configuration ├── errors.md # Error handling ``` -------------------------------- ### Named Vectors Map Example Source: https://github.com/qdrant/java-client/blob/master/_autodocs/types.md Represents multiple vectors associated with a point, keyed by name. ```java Map vectors = Map.of( "text", VectorFactory.vector(0.1f, 0.2f, 0.3f), "image", VectorFactory.vector(0.4f, 0.5f, 0.6f) ); ``` -------------------------------- ### Builder.build Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Builds and returns the configured `QdrantGrpcClient` instance. It may perform version compatibility checks if enabled. ```APIDOC ## Builder.build() ### Description Builds and returns the configured `QdrantGrpcClient`. Performs version compatibility check if enabled. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```java public QdrantGrpcClient build() ``` ### Returns - **QdrantGrpcClient** - The fully configured Qdrant gRPC client. ### Throws - Warning logged if version incompatibility detected (not fatal unless incompatible). ### Example ```java QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder("localhost") .withApiKey("key123") .withTimeout(Duration.ofSeconds(60)) .build(); ``` ``` -------------------------------- ### Get Underlying gRPC Client Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Retrieves the internal gRPC client instance for advanced or custom use cases. ```java public QdrantGrpcClient grpcClient() ``` -------------------------------- ### Create QdrantGrpcClient with Host and Port Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Instantiates a QdrantGrpcClient with an explicit host and port number. ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost", 6334, false).build(); ``` -------------------------------- ### Create QdrantGrpcClient with Host Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Instantiates a QdrantGrpcClient by specifying the host. The default port (6334) will be used. ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost").build(); ``` -------------------------------- ### Create Basic Qdrant Client Source: https://github.com/qdrant/java-client/blob/master/README.md Instantiate a Qdrant client to connect to the default Qdrant instance running on localhost:6334. This client uses gRPC for communication. ```java QdrantClient client = new QdrantClient(QdrantGrpcClient.newBuilder("localhost").build()); ``` -------------------------------- ### Configure SLF4J Logging with Logback Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Sets up SLF4J logging using Logback, enabling DEBUG level logging for the Qdrant client. This configuration should be placed in your `logback.xml` file. ```xml %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n ``` -------------------------------- ### Resource Management with try-with-resources Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Ensure proper cleanup of Qdrant client connections by using the try-with-resources statement for automatic resource management. ```java try (QdrantClient client = new QdrantClient(grpcClient)) { // Use client } ``` -------------------------------- ### Build Project on Windows Source: https://github.com/qdrant/java-client/blob/master/CONTRIBUTING.md Run the Gradle build task on Windows to download dependencies, build the project, and execute integration tests. Ensure Docker is running. ```bash .\gradlew.bat build ``` -------------------------------- ### Read Environment Variables for Client Configuration Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Demonstrates how to read environment variables for API key, host, and port to configure the Qdrant client. Ensure these variables are set in your application's environment. ```java String apiKey = System.getenv("QDRANT_API_KEY"); String host = System.getenv("QDRANT_HOST", "localhost"); int port = Integer.parseInt(System.getenv("QDRANT_PORT", "6334")); QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder(host, port) .withApiKey(apiKey) .build() ); ``` -------------------------------- ### Filtered Deletion Operation Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Delete points from a collection based on specific filter conditions. This example deletes points where the 'status' is 'active' and 'price' is between 10 and 100. ```java Filter filter = Filter.newBuilder() .addMust(ConditionFactory.matchKeyword("status", "active")) .addMust(ConditionFactory.range("price", Range.newBuilder().setGte(10).setLte(100).build())) .build(); client.deleteAsync("collection", filter).get(); ``` -------------------------------- ### QdrantClient Constructor Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Initializes a new QdrantClient instance using a provided gRPC client. This is the primary way to establish a connection to the Qdrant database. ```APIDOC ## QdrantClient(QdrantGrpcClient grpcClient) ### Description Initializes a new QdrantClient instance. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder("localhost").build(); QdrantClient client = new QdrantClient(grpcClient); ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A (Constructor) ``` -------------------------------- ### Build QdrantGrpcClient with API Key and Timeout Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Constructs a QdrantGrpcClient instance, applying an API key for authentication and setting a specific timeout for requests. This is a common configuration for production environments. ```java QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder("localhost") .withApiKey("key123") .withTimeout(Duration.ofSeconds(60)) .build(); ``` -------------------------------- ### Low-Level gRPC Client Builders Source: https://github.com/qdrant/java-client/blob/master/_autodocs/INDEX.md Provides methods for building a low-level gRPC client, allowing for direct interaction with Qdrant via gRPC with various configuration options. ```APIDOC ## Low-Level gRPC Client ### Description The `QdrantGrpcClient` allows for direct gRPC communication with Qdrant, offering fine-grained control over the connection and authentication. ### Builders - `newBuilder(String host)`: Creates a client builder for localhost with default settings. - `newBuilder(String host, int port)`: Creates a client builder for a specified host and port. - `newBuilder(String host, int port, boolean useTransportLayerSecurity)`: Creates a client builder with custom host, port, and TLS configuration. - `newBuilder(String host, int port, boolean useTransportLayerSecurity, boolean checkCompatibility)`: Creates a client builder with full control over connection parameters, including compatibility checks. - `newBuilder(ManagedChannel channel)`: Creates a client builder using an existing `ManagedChannel`. ### Builder Methods - `withApiKey(String apiKey)`: Configures API key authentication. - `withHeaders(Map headers)`: Adds custom headers to the client. - `withCallCredentials(CallCredentials credentials)`: Applies advanced authentication credentials. - `withTimeout(Duration timeout)`: Sets the default timeout for gRPC calls. - `build()`: Constructs and returns the `QdrantGrpcClient` instance. ``` -------------------------------- ### Custom TLS Configuration for Qdrant Client Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Demonstrates how to create a QdrantGrpcClient with a custom TLS configuration, specifying a trust manager to verify the server's certificate. This is useful when using self-signed certificates or custom certificate authorities. ```java ManagedChannel channel = Grpc.newChannelBuilder( "localhost:6334", TlsChannelCredentials.newBuilder() .trustManager(new File("ssl/ca.crt")) .build()) .build(); QdrantGrpcClient client = QdrantGrpcClient.newBuilder(channel, true) .withApiKey("key123") .build(); ``` -------------------------------- ### QdrantGrpcClient Builders Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Instances of QdrantGrpcClient are created using static builder methods. These methods allow for flexible configuration of the connection, including host, port, TLS settings, and compatibility checks. ```APIDOC ## QdrantGrpcClient.newBuilder(String host) ### Description Creates a builder for a client connecting to a Qdrant instance. ### Method `public static Builder newBuilder(String host)` ### Parameters #### Path Parameters - **host** (String) - Required - Hostname or IP address (port 6334 is used by default) ### Returns `Builder` ### Example ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost").build(); ``` ## QdrantGrpcClient.newBuilder(String host, int port) ### Description Creates a builder with explicit host and port. ### Method `public static Builder newBuilder(String host, int port)` ### Parameters #### Path Parameters - **host** (String) - Required - Hostname or IP address - **port** (int) - Required - Port number (typically 6334) ### Returns `Builder` ## QdrantGrpcClient.newBuilder(String host, int port, boolean useTransportLayerSecurity) ### Description Creates a builder with explicit TLS configuration. ### Method `public static Builder newBuilder(String host, int port, boolean useTransportLayerSecurity)` ### Parameters #### Path Parameters - **host** (String) - Required - Hostname or IP address - **port** (int) - Required - Port number - **useTransportLayerSecurity** (boolean) - Required - Enable TLS (true for production, false for testing) ### Returns `Builder` ### Example ```java // Plaintext for local testing QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost", 6334, false).build(); ``` ## QdrantGrpcClient.newBuilder(String host, int port, boolean useTransportLayerSecurity, boolean checkCompatibility) ### Description Provides full control over all initialization parameters. ### Method `public static Builder newBuilder(String host, int port, boolean useTransportLayerSecurity, boolean checkCompatibility)` ### Parameters #### Path Parameters - **host** (String) - Required - Hostname or IP address - **port** (int) - Required - Port number - **useTransportLayerSecurity** (boolean) - Required - Enable TLS - **checkCompatibility** (boolean) - Required - Check client-server version compatibility on startup ### Returns `Builder` ## QdrantGrpcClient.newBuilder(ManagedChannel channel) ### Description Creates a builder using an existing gRPC `ManagedChannel`. The channel will not be managed by the client (caller is responsible for shutdown). ### Method `public static Builder newBuilder(ManagedChannel channel)` ### Parameters #### Path Parameters - **channel** (ManagedChannel) - Required - Existing gRPC channel ### Returns `Builder` ### Example ```java ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 6334) .usePlaintext() .build(); QdrantGrpcClient client = QdrantGrpcClient.newBuilder(channel).build(); // Caller must close channel channel.shutdown(); ``` ## QdrantGrpcClient.newBuilder(ManagedChannel channel, boolean shutdownChannelOnClose) ### Description Creates a builder with control over channel lifecycle. ### Method `public static Builder newBuilder(ManagedChannel channel, boolean shutdownChannelOnClose)` ### Parameters #### Path Parameters - **channel** (ManagedChannel) - Required - Existing gRPC channel - **shutdownChannelOnClose** (boolean) - Required - Whether to shutdown channel on client close ### Returns `Builder` ## QdrantGrpcClient.newBuilder(ManagedChannel channel, boolean shutdownChannelOnClose, boolean checkCompatibility) ### Description Provides full control when using an existing channel. ### Method `public static Builder newBuilder(ManagedChannel channel, boolean shutdownChannelOnClose, boolean checkCompatibility)` ### Parameters #### Path Parameters - **channel** (ManagedChannel) - Required - Existing gRPC channel - **shutdownChannelOnClose** (boolean) - Required - Whether to shutdown channel on client close - **checkCompatibility** (boolean) - Required - Check client-server version compatibility on startup ### Returns `Builder` ``` -------------------------------- ### Handle Authentication Failure Source: https://github.com/qdrant/java-client/blob/master/_autodocs/errors.md Ensure a valid API key is configured and provided when initializing the Qdrant client. ```java String apiKey = getApiKeyFromSecureStorage(); if (apiKey == null || apiKey.isEmpty()) { throw new IllegalStateException("API key not configured"); } QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("api.qdrant.io") .withApiKey(apiKey) .build() ); ``` -------------------------------- ### Main Client Methods Source: https://github.com/qdrant/java-client/blob/master/_autodocs/INDEX.md The main Qdrant client provides high-level methods for interacting with Qdrant collections, points, and other features, categorized for ease of use. ```APIDOC ## Main Client ### Description The `QdrantClient` offers a high-level interface for performing various operations on Qdrant, including collection management, point manipulation, search, and more. ### Methods by Category #### Health - `healthCheckAsync()`: Checks the health status of the Qdrant instance. #### Collections - `createCollectionAsync(CreateCollection request)`: Creates a new collection. - `deleteCollectionAsync(DeleteCollection request)`: Deletes an existing collection. - `listCollectionsAsync()`: Lists all available collections. - `getCollectionInfoAsync(GetCollectionInfo request)`: Retrieves detailed information about a specific collection. - `collectionExistsAsync(CollectionExists request)`: Checks if a collection exists. - `updateCollectionAsync(UpdateCollection request)`: Updates an existing collection's configuration. #### Aliases - `createAliasAsync(CreateAlias request)`: Creates an alias for a collection. - `deleteAliasAsync(DeleteAlias request)`: Deletes an alias. - `renameAliasAsync(RenameAlias request)`: Renames an existing alias. - `listAliasesAsync()`: Lists all aliases. - `listCollectionAliasesAsync(ListCollectionAliases request)`: Lists aliases for a specific collection. #### Shard Keys - `createShardKeyAsync(CreateShardKey request)`: Creates a shard key for a collection. - `deleteShardKeyAsync(DeleteShardKey request)`: Deletes a shard key. - `listShardKeysAsync(ListShardKeys request)`: Lists shard keys for a collection. #### Points - `upsertAsync(UpsertPoints request)`: Inserts or updates points in a collection. - `deleteAsync(DeletePoints request)`: Deletes points from a collection. - `retrieveAsync(RetrievePoints request)`: Retrieves points by their IDs. - `countAsync(CountPoints request)`: Counts the number of points in a collection. #### Vectors - `updateVectorsAsync(UpdateVectors request)`: Updates vectors for existing points. - `deleteVectorsAsync(DeleteVectors request)`: Deletes vectors from points. - `createVectorNameAsync(CreateVectorName request)`: Creates a named vector configuration. - `deleteVectorNameAsync(DeleteVectorName request)`: Deletes a named vector configuration. #### Payload - `setPayloadAsync(SetPayload request)`: Sets or updates the payload for specified points. - `overwritePayloadAsync(OverwritePayload request)`: Overwrites the payload for specified points. - `deletePayloadAsync(DeletePayload request)`: Deletes payload fields for specified points. - `clearPayloadAsync(ClearPayload request)`: Clears all payload data for specified points. - `createPayloadIndexAsync(CreatePayloadIndex request)`: Creates a payload index. - `deletePayloadIndexAsync(DeletePayloadIndex request)`: Deletes a payload index. #### Search - `searchAsync(SearchPoints request)`: Performs a similarity search for points. - `searchBatchAsync(SearchBatchPoints request)`: Performs batch similarity searches. - `searchGroupsAsync(SearchGroups request)`: Performs grouped similarity searches. - `scrollAsync(ScrollPoints request)`: Scrolls through points in a collection. #### Recommend - `recommendAsync(RecommendPoints request)`: Recommends points based on given examples. - `recommendBatchAsync(RecommendBatchPoints request)`: Performs batch recommendation searches. - `recommendGroupsAsync(RecommendGroups request)`: Performs grouped recommendation searches. #### Discover - `discoverAsync(DiscoverPoints request)`: Discovers points based on context. - `discoverBatchAsync(DiscoverBatchPoints request)`: Performs batch discovery searches. #### Query - `queryAsync(QueryPoints request)`: Executes a general query for points. - `queryBatchAsync(QueryBatchPoints request)`: Executes batch queries. - `queryGroupsAsync(QueryGroups request)`: Executes grouped queries. #### Snapshots - `createSnapshotAsync(CreateSnapshot request)`: Creates a snapshot of the collection. - `deleteSnapshotAsync(DeleteSnapshot request)`: Deletes a snapshot. - `listSnapshotAsync()`: Lists available snapshots. ``` -------------------------------- ### Manage QdrantGrpcClient Lifecycle with Try-with-Resources Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Shows how to properly manage the lifecycle of a QdrantGrpcClient using a try-with-resources statement. This ensures the underlying gRPC channel is automatically closed when the block is exited, preventing resource leaks. ```java try (QdrantGrpcClient client = QdrantGrpcClient.newBuilder("localhost").build()) { // Use client // Automatically closed on exit } ``` -------------------------------- ### Build Project on OSX/Linux Source: https://github.com/qdrant/java-client/blob/master/CONTRIBUTING.md Execute the Gradle build task on macOS or Linux to fetch dependencies, compile the project, and run integration tests. Docker must be active. ```bash ./gradlew build ``` -------------------------------- ### Plaintext Connection for Testing Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Establishes a plaintext gRPC connection to a local Qdrant instance on a specific port. This is unsafe for production and intended for local testing only. ```java QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("localhost", 6334, false) .build() ); ``` -------------------------------- ### Production Connection with TLS and API Key Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Configures a client for production use, connecting to a remote Qdrant instance with TLS enabled and authenticating using an API key. A timeout is also set for requests. ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("api.qdrant.io", 6334, true) .withApiKey("sk-proj-xxxxx") .withTimeout(Duration.ofSeconds(30)) .build(); ``` -------------------------------- ### Create QdrantGrpcClient with Existing ManagedChannel Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Instantiates a QdrantGrpcClient using a pre-existing gRPC ManagedChannel. The caller is responsible for managing the lifecycle of the provided channel. ```java ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 6334) .usePlaintext() .build(); QdrantGrpcClient client = QdrantGrpcClient.newBuilder(channel).build(); // Caller must close channel channel.shutdown(); ``` -------------------------------- ### Configure Client with External ManagedChannel Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Configures the Qdrant client using an externally managed gRPC channel. Remember to manually close the channel if `shutdownChannelOnClose` is set to false. ```java ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 6334) .usePlaintext() .build(); QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder(channel, false).build() ); try { // Use client } finally { client.close(); // Caller must close channel since shutdownChannelOnClose=false channel.shutdown(); } ``` -------------------------------- ### Catching QdrantException in Java Source: https://github.com/qdrant/java-client/blob/master/_autodocs/errors.md Demonstrates how to catch and inspect `QdrantException` when an asynchronous operation fails. This is useful for distinguishing Qdrant-specific errors from other potential exceptions. ```java try { client.createCollectionAsync("my_collection", vectorParams).get(); } catch (ExecutionException e) { if (e.getCause() instanceof QdrantException) { System.err.println("Qdrant error: " + e.getCause().getMessage()); } } ``` -------------------------------- ### Configure API Key Authentication Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Configures API key authentication for the QdrantGrpcClient. The API key is sent in the request metadata. ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("api.qdrant.io") .withApiKey("your-api-key-here") .build(); ``` -------------------------------- ### Create Qdrant Client with TLS and API Key Source: https://github.com/qdrant/java-client/blob/master/README.md Configure a Qdrant client to use TLS with a specific CA certificate for server verification and authenticate using an API key. This provides a secure connection. ```java ManagedChannel channel = Grpc.newChannelBuilder( "localhost:6334", TlsChannelCredentials.newBuilder() .trustManager(new File("ssl/ca.crt")) .build()) .build(); QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder(channel) .withApiKey("") .build()); ``` -------------------------------- ### createCollectionAsync(String collectionName, VectorParams vectorParams) Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Creates a new Qdrant collection with a specified name and vector parameters. This is a fundamental operation for setting up data storage. ```APIDOC ## createCollectionAsync(String collectionName, VectorParams vectorParams) ### Description Creates a new collection with default vector configuration. ### Method POST (Implied) ### Endpoint /collections/{collection_name} ### Parameters #### Path Parameters - **collection_name** (string) - Required - Name of the collection to create. #### Query Parameters None #### Request Body - **vector_params** (VectorParams) - Required - Vector parameters (size and distance metric). ### Request Example ```java CollectionOperationResponse response = client.createCollectionAsync( "my_collection", VectorParams.newBuilder() .setSize(384) .setDistance(Distance.Cosine) .build() ).get(); ``` ### Response #### Success Response (200) - **status** (string) - The status of the collection operation. - **result** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "status": "ok", "result": true } ``` ``` -------------------------------- ### Create a Qdrant Collection Source: https://github.com/qdrant/java-client/blob/master/README.md Use this snippet to create a new collection in Qdrant. Ensure you specify the collection name, vector parameters including distance metric and size. ```java client.createCollectionAsync("{collection_name}", VectorParams.newBuilder() .setDistance(Distance.Cosine) .setSize(4) .build()) .get(); ``` -------------------------------- ### Create Context Query Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Creates a context search query to find points near a given point in payload space. ```java public static Query context(ContextInput input) ``` -------------------------------- ### Builder.withApiKey(String apiKey) Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Configures API key authentication for the gRPC client. The API key is sent in the request metadata. ```APIDOC ## Builder.withApiKey(String apiKey) ### Description Configures API key authentication. The key is sent in request metadata. ### Method `public Builder withApiKey(String apiKey)` ### Parameters #### Path Parameters - **apiKey** (String) - Required - API key for authentication ### Returns `Builder` (for method chaining) ### Example ```java QdrantGrpcClient client = QdrantGrpcClient.newBuilder("api.qdrant.io") .withApiKey("your-api-key-here") .build(); ``` ``` -------------------------------- ### Async API Usage with Callbacks Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Illustrates handling asynchronous operations using Guava's Futures and FutureCallback for non-blocking I/O. ```java // Blocking (not recommended for production) UpdateResult result = client.upsertAsync("collection", points).get(); // Async with callbacks Futures.addCallback( client.upsertAsync("collection", points), new FutureCallback() { public void onSuccess(UpdateResult result) { ... } public void onFailure(Throwable e) { ... } } ); ``` -------------------------------- ### Snapshot Management Source: https://github.com/qdrant/java-client/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Methods for managing snapshots of the Qdrant index, including creating, listing, and deleting snapshots. ```APIDOC ## Snapshot Management This section covers methods for managing snapshots. ### Methods - `createSnapshotAsync` (2 overloads) - `listSnapshotAsync` (2 overloads) - `deleteSnapshotAsync` (2 overloads) - `createFullSnapshotAsync` (2 overloads) - `listFullSnapshotsAsync` (1 overload) - `deleteFullSnapshotAsync` (2 overloads) ``` -------------------------------- ### Factory Classes Source: https://github.com/qdrant/java-client/blob/master/_autodocs/DOCUMENTATION_SUMMARY.txt Reference for convenience factory classes used to construct various Qdrant objects, including methods for creating PointIds, Vectors, Conditions, and more. ```APIDOC ## Factory Classes Reference ### Description This document details the various factory classes provided to simplify the creation of Qdrant-specific data structures and objects. ### Available Factory Classes and Methods: - **ValueFactory**: 7 methods for creating value objects. - **PointIdFactory**: 2 methods for creating PointIds (numeric or UUID). - **VectorFactory**: 6 methods for creating dense, sparse, or multi-vectors. - **VectorsFactory**: 5 methods for creating vector containers. - **ConditionFactory**: 11 methods for building query conditions. - **QueryFactory**: 6 methods for constructing query objects. - **WithPayloadSelectorFactory**: 3 methods for configuring payload selection. - **WithVectorsSelectorFactory**: 2 methods for configuring vector selection. - **VectorInputFactory**: 5 methods for creating vector inputs. - **TargetVectorFactory**: 1 method for specifying target vectors. ``` -------------------------------- ### Timeout Handling for Client Operations Source: https://github.com/qdrant/java-client/blob/master/_autodocs/errors.md Demonstrates how to set a specific timeout for a client operation and catch `DEADLINE_EXCEEDED` gRPC errors. Provides a user-friendly message suggesting solutions. ```java try { client.upsertAsync("collection", points, Duration.ofSeconds(5)).get(); } catch (ExecutionException e) { if (e.getCause() instanceof StatusRuntimeException) { StatusRuntimeException grpc = (StatusRuntimeException) e.getCause(); if (grpc.getStatus().getCode() == Status.Code.DEADLINE_EXCEEDED) { System.err.println("Operation timed out. Increase timeout or reduce batch size."); } } } ``` -------------------------------- ### grpcClient Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Returns the underlying gRPC client instance for advanced usage scenarios. ```APIDOC ## grpcClient ### Description Returns the underlying gRPC client for advanced use cases. ### Method Signature ```java public QdrantGrpcClient grpcClient() ``` ### Returns `QdrantGrpcClient` - The underlying gRPC client. ``` -------------------------------- ### Using an Existing ManagedChannel Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Integrates the Qdrant client with a pre-configured gRPC ManagedChannel, allowing for advanced channel customization and lifecycle management. The client is configured to shut down the channel when it is closed. ```java ManagedChannel channel = ManagedChannelBuilder .forAddress("localhost", 6334) .usePlaintext() .maxRetryAttempts(3) .retryBufferSize(1000000) .build(); QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder(channel, true) .withTimeout(Duration.ofSeconds(30)) .build() ); // Channel shutdown handled by client try { // Use client } finally { client.close(); } ``` -------------------------------- ### snapshots() Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantGrpcClient.md Provides access to the gRPC service stub for snapshot operations. This stub is used for managing snapshots of your Qdrant data, such as creating and restoring snapshots. ```APIDOC ## snapshots() ### Description Returns the gRPC service stub for snapshot operations. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```java public SnapshotsFutureStub snapshots() ``` ### Returns - **SnapshotsFutureStub** - The stub for performing snapshot-related operations. ### Example ```java // Example: Create snapshot // CreateSnapshotRequest request = CreateSnapshotRequest.newBuilder().setCollectionName("my_collection").build(); // grpcClient.snapshots().createSnapshot(request); ``` ``` -------------------------------- ### Create Qdrant Client with Channel Shutdown Source: https://github.com/qdrant/java-client/blob/master/README.md Configure a Qdrant client to automatically shut down the managed channel when the client is closed. This is useful for managing resource cleanup. ```java ManagedChannel channel = Grpc.newChannelBuilder( "localhost:6334", TlsChannelCredentials.create()) .build(); QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder(channel, true) .withApiKey("") .build()); ``` -------------------------------- ### Search for Similar Vectors Source: https://github.com/qdrant/java-client/blob/master/README.md Perform a basic vector search in a Qdrant collection. Specify the collection name, the query vector, and the desired limit for results. ```java List points = client .searchAsync( SearchPoints.newBuilder() .setCollectionName("{collection_name}") .addAllVector(List.of(0.6235f, 0.123f, 0.532f, 0.123f)) .setLimit(5) .build()) .get(); ``` -------------------------------- ### Create Vector instances Source: https://github.com/qdrant/java-client/blob/master/_autodocs/types.md Use VectorFactory to create dense, sparse, or multi-dense vector instances. ```java VectorFactory.vector(0.1f, 0.2f, 0.3f) // Dense vector VectorFactory.vector(List.of(0.1f, 0.2f)) // Dense from list VectorFactory.vector(List.of(1.0f), List.of(0)) // Sparse vector VectorFactory.multiVector(new float[][] {...}) // Multi-vector ``` -------------------------------- ### Handle Asynchronous Operation Results with ListenableFuture Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Shows how to attach listeners to a ListenableFuture to handle both success and failure scenarios for asynchronous Qdrant operations. ```java client.createCollectionAsync("my_collection", vectorParams) .addListener(() -> { // Handle success }, MoreExecutors.directExecutor()) .addListener(() -> { // Handle failure }, MoreExecutors.directExecutor()); ``` -------------------------------- ### Configure SLF4J Logging with Log4j2 Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Configures SLF4J logging using Log4j2, setting the Qdrant client's log level to DEBUG. This configuration should be placed in your `log4j2.xml` file. ```xml ``` -------------------------------- ### Maven Runtime Dependency for gRPC Source: https://github.com/qdrant/java-client/blob/master/_autodocs/README.md Include this runtime dependency for the gRPC transport used by the Qdrant Java Client. ```xml io.grpc grpc-netty-shaded 1.75.0 runtime ``` -------------------------------- ### listAliasesAsync Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Lists all aliases across all collections in the Qdrant instance. ```APIDOC ## listAliasesAsync ### Description Lists all aliases across all collections. ### Method `listAliasesAsync()` ### Returns `ListenableFuture>` ``` -------------------------------- ### Build Point with Named Vectors Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Illustrates creating a PointStruct with named vectors for different embedding types and including a payload. ```java PointStruct point = PointStruct.newBuilder() .setId(PointIdFactory.id(1)) .setVectors(VectorsFactory.namedVectors(Map.of( "text_embedding", VectorFactory.vector(0.1f, 0.2f, 0.3f), "image_embedding", VectorFactory.vector(0.4f, 0.5f, 0.6f) ))) .putAllPayload(payload) .build(); ``` -------------------------------- ### Custom Port and Explicit TLS Configuration Source: https://github.com/qdrant/java-client/blob/master/_autodocs/configuration.md Configures connection to a Qdrant instance on a custom port (6335) with explicit TLS enabled and API key authentication. ```java QdrantClient client = new QdrantClient( QdrantGrpcClient.newBuilder("qdrant.example.com", 6335, true) .withApiKey("key123") .build() ); ``` -------------------------------- ### listCollectionsAsync Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Retrieves the names of all existing collections in the Qdrant instance. ```APIDOC ## listCollectionsAsync ### Description Retrieves names of all existing collections. ### Method `listCollectionsAsync()` ### Returns `ListenableFuture>` containing collection names ### Example ```java List collections = client.listCollectionsAsync().get(); collections.forEach(System.out::println); ``` ``` -------------------------------- ### Maven Dependency for Qdrant Java Client Source: https://github.com/qdrant/java-client/blob/master/README.md Add this dependency to your Maven build configuration to include the Qdrant Java Client library. Requires Java 8 or above. ```xml io.qdrant client 1.18.1 ``` -------------------------------- ### Build Payload for Upsert Operation Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/FactoryClasses.md Demonstrates how to construct a payload map with various data types for an upsert operation. ```java Map payload = Map.of( "name", ValueFactory.value("Product A"), "price", ValueFactory.value(99.99), "in_stock", ValueFactory.value(true), "tags", ValueFactory.list(List.of( ValueFactory.value("electronics"), ValueFactory.value("sale") )) ); ``` -------------------------------- ### Gradle Dependency for Qdrant Java Client Source: https://github.com/qdrant/java-client/blob/master/README.md Add this dependency to your Gradle build configuration to include the Qdrant Java Client library. Requires Java 8 or above. ```gradle implementation 'io.qdrant:client:1.18.1' ``` -------------------------------- ### Create Shard Key Async Source: https://github.com/qdrant/java-client/blob/master/_autodocs/api-reference/QdrantClient.md Asynchronously creates a shard key for a specified collection. ```java public ListenableFuture createShardKeyAsync( CreateShardKeyRequest createShardKey) ```