New tutorial: "Secure a Self-Hosted Qdrant Instance" (#2385)

* Initial commit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Edits

* Edits

* Fix links

* Use 'true' instead of '1' in QDRANT__SERVICE__ENABLE_TLS example

* Review feedback

* Add link from Security page

* Update stack designation on overview page

* Update qdrant-landing/content/documentation/tutorials-operations/secure-qdrant.md

Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
This commit is contained in:
Abdon Pijpelink
2026-06-01 16:09:56 +02:00
committed by GitHub
co-authored by Claude Sonnet 4.6 István Zoltán Szabó
parent bde1efaf72
commit 9ba29ff4fa
47 changed files with 1915 additions and 4 deletions
@@ -0,0 +1,93 @@
// @block-start upsert-no-auth
using Qdrant.Client;
using Qdrant.Client.Grpc;
public class Snippet
{
public static async Task Run()
{
var client = new QdrantClient(host: "localhost", port: 6334, https: true);
try
{
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // Unauthenticated
}
// @block-end upsert-no-auth
// @block-start upsert-admin-key
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-admin-key");
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
// @block-end upsert-admin-key
// @block-start delete-read-only-key
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-read-only-key");
try
{
await client.DeleteAsync(collectionName: "my_collection", ids: (ulong[])[1]);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
// @block-end delete-read-only-key
// @block-start upsert-jwt-rw-collection
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
// @block-end upsert-jwt-rw-collection
// @block-start upsert-jwt-ro-collection
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
try
{
await client.UpsertAsync(
collectionName: "other_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
// @block-end upsert-jwt-ro-collection
}
}
@@ -0,0 +1,79 @@
```csharp
using Qdrant.Client;
using Qdrant.Client.Grpc;
var client = new QdrantClient(host: "localhost", port: 6334, https: true);
try
{
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // Unauthenticated
}
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-admin-key");
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-read-only-key");
try
{
await client.DeleteAsync(collectionName: "my_collection", ids: (ulong[])[1]);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
try
{
await client.UpsertAsync(
collectionName: "other_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
```
@@ -0,0 +1,12 @@
```csharp
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-read-only-key");
try
{
await client.DeleteAsync(collectionName: "my_collection", ids: (ulong[])[1]);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
```
@@ -0,0 +1,19 @@
```go
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-read-only-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Delete(context.Background(), &qdrant.DeletePoints{
CollectionName: "my_collection",
Points: qdrant.NewPointsSelector(qdrant.NewIDNum(1)),
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
```
@@ -0,0 +1,12 @@
```java
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-read-only-key")
.build());
try {
client.deleteAsync("my_collection", List.of(id(1))).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
```
@@ -0,0 +1,11 @@
```python
client = QdrantClient(url="https://localhost:6333", api_key="my-read-only-key")
try:
client.delete(
collection_name="my_collection",
points_selector=models.PointIdsList(points=[1]),
)
except Exception as e:
print(e) # 403 Forbidden
```
@@ -0,0 +1,16 @@
```rust
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-read-only-key")
.build()?;
let result = client
.delete_points(
DeletePointsBuilder::new("my_collection").points(PointsIdsList {
ids: vec![1.into()],
}),
)
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
```
@@ -0,0 +1,9 @@
```typescript
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-read-only-key" });
try {
await client.delete("my_collection", { points: [1] });
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
```
@@ -0,0 +1,127 @@
```go
import (
"context"
"fmt"
"github.com/qdrant/go-client/qdrant"
)
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
if err != nil {
fmt.Println(err) // Unauthenticated
}
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-admin-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-read-only-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Delete(context.Background(), &qdrant.DeletePoints{
CollectionName: "my_collection",
Points: qdrant.NewPointsSelector(qdrant.NewIDNum(1)),
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "other_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
```
@@ -0,0 +1,88 @@
```java
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.VectorsFactory.vectors;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Collections.Distance;
import io.qdrant.client.grpc.Collections.VectorParams;
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true).build());
try {
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // UNAUTHENTICATED
}
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-admin-key")
.build());
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-read-only-key")
.build());
try {
client.deleteAsync("my_collection", List.of(id(1))).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
try {
client.upsertAsync("other_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
```
@@ -0,0 +1,57 @@
```python
from qdrant_client import QdrantClient, models
client = QdrantClient(url="https://localhost:6333")
try:
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
except Exception as e:
print(e) # 401 Unauthorized
client = QdrantClient(url="https://localhost:6333", api_key="my-admin-key")
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
client = QdrantClient(url="https://localhost:6333", api_key="my-read-only-key")
try:
client.delete(
collection_name="my_collection",
points_selector=models.PointIdsList(points=[1]),
)
except Exception as e:
print(e) # 403 Forbidden
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
try:
client.upsert(
collection_name="other_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
except Exception as e:
print(e) # 403 Forbidden
```
@@ -0,0 +1,87 @@
```rust
use qdrant_client::qdrant::{
CreateCollectionBuilder, DeletePointsBuilder, Distance, PointStruct, PointsIdsList,
UpsertPointsBuilder, VectorParamsBuilder,
};
use qdrant_client::Qdrant;
let client = Qdrant::from_url("https://localhost:6334").build()?;
let result = client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
let result = client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-admin-key")
.build()?;
client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await?;
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-read-only-key")
.build()?;
let result = client
.delete_points(
DeletePointsBuilder::new("my_collection").points(PointsIdsList {
ids: vec![1.into()],
}),
)
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await?;
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
let result = client
.upsert_points(UpsertPointsBuilder::new(
"other_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
```
@@ -0,0 +1,51 @@
```typescript
import { QdrantClient } from "@qdrant/js-client-rest";
client = new QdrantClient({ url: "https://localhost:6333" });
try {
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
} catch (e: any) {
console.error(e.message); // 401 Unauthorized
}
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-admin-key" });
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-read-only-key" });
try {
await client.delete("my_collection", { points: [1] });
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
await client.upsert("my_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
try {
await client.upsert("other_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
```
@@ -0,0 +1,16 @@
```csharp
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "my-admin-key");
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
```
@@ -0,0 +1,29 @@
```go
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-admin-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
```
@@ -0,0 +1,19 @@
```java
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-admin-key")
.build());
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
```
@@ -0,0 +1,13 @@
```python
client = QdrantClient(url="https://localhost:6333", api_key="my-admin-key")
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
```
@@ -0,0 +1,19 @@
```rust
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-admin-key")
.build()?;
client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await?;
```
@@ -0,0 +1,11 @@
```typescript
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-admin-key" });
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
```
@@ -0,0 +1,18 @@
```csharp
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
try
{
await client.UpsertAsync(
collectionName: "other_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // PermissionDenied
}
```
@@ -0,0 +1,24 @@
```go
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "other_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
```
@@ -0,0 +1,17 @@
```java
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
try {
client.upsertAsync("other_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
```
@@ -0,0 +1,11 @@
```python
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
try:
client.upsert(
collection_name="other_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
except Exception as e:
print(e) # 403 Forbidden
```
@@ -0,0 +1,15 @@
```rust
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
let result = client
.upsert_points(UpsertPointsBuilder::new(
"other_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
```
@@ -0,0 +1,11 @@
```typescript
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
try {
await client.upsert("other_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
```
@@ -0,0 +1,11 @@
```csharp
client = new QdrantClient(host: "localhost", port: 6334, https: true, apiKey: "<your-jwt>");
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 2, Vectors = new[] { 0.5f, 0.6f, 0.7f, 0.8f } }
}
);
```
@@ -0,0 +1,21 @@
```go
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
```
@@ -0,0 +1,13 @@
```java
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
```
@@ -0,0 +1,8 @@
```python
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
```
@@ -0,0 +1,12 @@
```rust
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await?;
```
@@ -0,0 +1,7 @@
```typescript
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
await client.upsert("my_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
```
@@ -0,0 +1,26 @@
```csharp
using Qdrant.Client;
using Qdrant.Client.Grpc;
var client = new QdrantClient(host: "localhost", port: 6334, https: true);
try
{
await client.CreateCollectionAsync(
collectionName: "my_collection",
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
);
await client.UpsertAsync(
collectionName: "my_collection",
points: new List<PointStruct>
{
new() { Id = 1, Vectors = new[] { 0.1f, 0.2f, 0.3f, 0.4f } }
}
);
}
catch (Exception e)
{
Console.WriteLine(e.Message); // Unauthenticated
}
```
@@ -0,0 +1,38 @@
```go
import (
"context"
"fmt"
"github.com/qdrant/go-client/qdrant"
)
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
if err != nil {
fmt.Println(err) // Unauthenticated
}
```
@@ -0,0 +1,31 @@
```java
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.VectorsFactory.vectors;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Collections.Distance;
import io.qdrant.client.grpc.Collections.VectorParams;
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true).build());
try {
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // UNAUTHENTICATED
}
```
@@ -0,0 +1,18 @@
```python
from qdrant_client import QdrantClient, models
client = QdrantClient(url="https://localhost:6333")
try:
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
except Exception as e:
print(e) # 401 Unauthorized
```
@@ -0,0 +1,23 @@
```rust
let client = Qdrant::from_url("https://localhost:6334").build()?;
let result = client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
let result = client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
```
@@ -0,0 +1,17 @@
```typescript
import { QdrantClient } from "@qdrant/js-client-rest";
client = new QdrantClient({ url: "https://localhost:6333" });
try {
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
} catch (e: any) {
console.error(e.message); // 401 Unauthorized
}
```
@@ -0,0 +1,143 @@
package snippet
// @block-start upsert-no-auth
import (
"context"
"fmt"
"github.com/qdrant/go-client/qdrant"
)
func Main() {
// @hide-start
var client *qdrant.Client
var err error
// @hide-end
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
if err != nil {
fmt.Println(err) // Unauthenticated
}
// @block-end upsert-no-auth
// @block-start upsert-admin-key
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-admin-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
CollectionName: "my_collection",
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
Size: 4,
Distance: qdrant.Distance_Cosine,
}),
})
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(1),
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
},
},
})
// @block-end upsert-admin-key
// @block-start delete-read-only-key
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "my-read-only-key",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Delete(context.Background(), &qdrant.DeletePoints{
CollectionName: "my_collection",
Points: qdrant.NewPointsSelector(qdrant.NewIDNum(1)),
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
// @block-end delete-read-only-key
// @block-start upsert-jwt-rw-collection
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "my_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
// @block-end upsert-jwt-rw-collection
// @block-start upsert-jwt-ro-collection
client, err = qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
APIKey: "<your-jwt>",
UseTLS: true,
})
if err != nil {
panic(err)
}
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "other_collection",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(2),
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
},
},
})
if err != nil {
fmt.Println(err) // PermissionDenied
}
// @block-end upsert-jwt-ro-collection
}
@@ -0,0 +1,107 @@
package com.example.snippets_amalgamation;
// @block-start upsert-no-auth
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.VectorsFactory.vectors;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Collections.Distance;
import io.qdrant.client.grpc.Collections.VectorParams;
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
public class Snippet {
public static void run() throws Exception {
// @hide-start
QdrantClient client = null;
// @hide-end
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true).build());
try {
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // UNAUTHENTICATED
}
// @block-end upsert-no-auth
// @block-start upsert-admin-key
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-admin-key")
.build());
client.createCollectionAsync("my_collection",
VectorParams.newBuilder()
.setSize(4)
.setDistance(Distance.Cosine)
.build()).get();
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
.build()
)).get();
// @block-end upsert-admin-key
// @block-start delete-read-only-key
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("my-read-only-key")
.build());
try {
client.deleteAsync("my_collection", List.of(id(1))).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
// @block-end delete-read-only-key
// @block-start upsert-jwt-rw-collection
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
client.upsertAsync("my_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
// @block-end upsert-jwt-rw-collection
// @block-start upsert-jwt-ro-collection
client = new QdrantClient(
QdrantGrpcClient.newBuilder("localhost", 6334, true)
.withApiKey("<your-jwt>")
.build());
try {
client.upsertAsync("other_collection", List.of(
PointStruct.newBuilder()
.setId(id(2))
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
.build()
)).get();
} catch (Exception e) {
System.out.println(e.getMessage()); // PERMISSION_DENIED
}
// @block-end upsert-jwt-ro-collection
}
}
@@ -0,0 +1,65 @@
# @block-start upsert-no-auth
from qdrant_client import QdrantClient, models
client = QdrantClient(url="https://localhost:6333")
try:
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
except Exception as e:
print(e) # 401 Unauthorized
# @block-end upsert-no-auth
# @block-start upsert-admin-key
client = QdrantClient(url="https://localhost:6333", api_key="my-admin-key")
client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
)
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4])],
)
# @block-end upsert-admin-key
# @block-start delete-read-only-key
client = QdrantClient(url="https://localhost:6333", api_key="my-read-only-key")
try:
client.delete(
collection_name="my_collection",
points_selector=models.PointIdsList(points=[1]),
)
except Exception as e:
print(e) # 403 Forbidden
# @block-end delete-read-only-key
# @block-start upsert-jwt-rw-collection
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
client.upsert(
collection_name="my_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
# @block-end upsert-jwt-rw-collection
# @block-start upsert-jwt-ro-collection
client = QdrantClient(url="https://localhost:6333", api_key="<your-jwt>")
try:
client.upsert(
collection_name="other_collection",
points=[models.PointStruct(id=2, vector=[0.5, 0.6, 0.7, 0.8])],
)
except Exception as e:
print(e) # 403 Forbidden
# @block-end upsert-jwt-ro-collection
@@ -0,0 +1,99 @@
use qdrant_client::qdrant::{
CreateCollectionBuilder, DeletePointsBuilder, Distance, PointStruct, PointsIdsList,
UpsertPointsBuilder, VectorParamsBuilder,
};
use qdrant_client::Qdrant;
pub async fn main() -> anyhow::Result<()> {
// @block-start upsert-no-auth
let client = Qdrant::from_url("https://localhost:6334").build()?;
let result = client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
let result = client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // Unauthorized
}
// @block-end upsert-no-auth
// @block-start upsert-admin-key
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-admin-key")
.build()?;
client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
)
.await?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(1, vec![0.1_f32, 0.2, 0.3, 0.4], [("source", "tutorial".into())])],
))
.await?;
// @block-end upsert-admin-key
// @block-start delete-read-only-key
let client = Qdrant::from_url("https://localhost:6334")
.api_key("my-read-only-key")
.build()?;
let result = client
.delete_points(
DeletePointsBuilder::new("my_collection").points(PointsIdsList {
ids: vec![1.into()],
}),
)
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
// @block-end delete-read-only-key
// @block-start upsert-jwt-rw-collection
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
client
.upsert_points(UpsertPointsBuilder::new(
"my_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await?;
// @block-end upsert-jwt-rw-collection
// @block-start upsert-jwt-ro-collection
let client = Qdrant::from_url("https://localhost:6334")
.api_key("<your-jwt>")
.build()?;
let result = client
.upsert_points(UpsertPointsBuilder::new(
"other_collection",
vec![PointStruct::new(2, vec![0.5_f32, 0.6, 0.7, 0.8], [("source", "tutorial".into())])],
))
.await;
if let Err(e) = result {
println!("{}", e); // PermissionDenied
}
// @block-end upsert-jwt-ro-collection
Ok(())
}
@@ -0,0 +1,63 @@
// @block-start upsert-no-auth
import { QdrantClient } from "@qdrant/js-client-rest";
// @hide-start
let client: QdrantClient;
// @hide-end
client = new QdrantClient({ url: "https://localhost:6333" });
try {
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
} catch (e: any) {
console.error(e.message); // 401 Unauthorized
}
// @block-end upsert-no-auth
// @block-start upsert-admin-key
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-admin-key" });
await client.createCollection("my_collection", {
vectors: { size: 4, distance: "Cosine" },
});
await client.upsert("my_collection", {
points: [{ id: 1, vector: [0.1, 0.2, 0.3, 0.4] }],
});
// @block-end upsert-admin-key
// @block-start delete-read-only-key
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "my-read-only-key" });
try {
await client.delete("my_collection", { points: [1] });
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
// @block-end delete-read-only-key
// @block-start upsert-jwt-rw-collection
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
await client.upsert("my_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
// @block-end upsert-jwt-rw-collection
// @block-start upsert-jwt-ro-collection
client = new QdrantClient({ url: "https://localhost:6333", apiKey: "<your-jwt>" });
try {
await client.upsert("other_collection", {
points: [{ id: 2, vector: [0.5, 0.6, 0.7, 0.8] }],
});
} catch (e: any) {
console.error(e.message); // 403 Forbidden
}
// @block-end upsert-jwt-ro-collection