mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-03 01:48:32 +02:00
Add worked with_lookup example
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
2b97750ade
commit
a6104d7b7a
+1
@@ -0,0 +1 @@
|
||||
Populate both collections for the `with_lookup` pattern. The `documents` collection holds one point per document with payload only. Each chunk in `chunks` carries a `document_id` payload value that matches the id of a point in `documents`.
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "documents",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new Dictionary<string, Vector>(),
|
||||
Payload =
|
||||
{
|
||||
["title"] = "Document A",
|
||||
["text"] = "This is document A",
|
||||
},
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Vectors = new Dictionary<string, Vector>(),
|
||||
Payload =
|
||||
{
|
||||
["title"] = "Document B",
|
||||
["text"] = "This is document B",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "chunks",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 0,
|
||||
Vectors = new float[] { 0.1f, 0.2f, 0.3f, 0.4f },
|
||||
Payload = { ["document_id"] = 1 },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new float[] { 0.5f, 0.6f, 0.7f, 0.8f },
|
||||
Payload = { ["document_id"] = 2 },
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "documents",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new Dictionary<string, Vector>(),
|
||||
Payload =
|
||||
{
|
||||
["title"] = "Document A",
|
||||
["text"] = "This is document A",
|
||||
},
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Vectors = new Dictionary<string, Vector>(),
|
||||
Payload =
|
||||
{
|
||||
["title"] = "Document B",
|
||||
["text"] = "This is document B",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "chunks",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 0,
|
||||
Vectors = new float[] { 0.1f, 0.2f, 0.3f, 0.4f },
|
||||
Payload = { ["document_id"] = 1 },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new float[] { 0.5f, 0.6f, 0.7f, 0.8f },
|
||||
Payload = { ["document_id"] = 2 },
|
||||
},
|
||||
}
|
||||
);
|
||||
```
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "documents",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{}),
|
||||
Payload: qdrant.NewValueMap(map[string]any{
|
||||
"title": "Document A",
|
||||
"text": "This is document A",
|
||||
}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{}),
|
||||
Payload: qdrant.NewValueMap(map[string]any{
|
||||
"title": "Document B",
|
||||
"text": "This is document B",
|
||||
}),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "chunks",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(0),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"document_id": 1}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"document_id": 2}),
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
```java
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ValueFactory.value;
|
||||
import static io.qdrant.client.VectorsFactory.namedVectors;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
QdrantClient client = new QdrantClient(
|
||||
QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.upsertAsync(
|
||||
"documents",
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(namedVectors(Map.of()))
|
||||
.putAllPayload(Map.of(
|
||||
"title", value("Document A"),
|
||||
"text", value("This is document A")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(2))
|
||||
.setVectors(namedVectors(Map.of()))
|
||||
.putAllPayload(Map.of(
|
||||
"title", value("Document B"),
|
||||
"text", value("This is document B")))
|
||||
.build())).get();
|
||||
|
||||
client.upsertAsync(
|
||||
"chunks",
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(0))
|
||||
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
|
||||
.putAllPayload(Map.of("document_id", value(1)))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
|
||||
.putAllPayload(Map.of("document_id", value(2)))
|
||||
.build())).get();
|
||||
```
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
```python
|
||||
client.upsert(
|
||||
collection_name="documents",
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector={},
|
||||
payload={"title": "Document A", "text": "This is document A"},
|
||||
),
|
||||
models.PointStruct(
|
||||
id=2,
|
||||
vector={},
|
||||
payload={"title": "Document B", "text": "This is document B"},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
client.upsert(
|
||||
collection_name="chunks",
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=0,
|
||||
vector=[0.1, 0.2, 0.3, 0.4],
|
||||
payload={"document_id": 1},
|
||||
),
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector=[0.5, 0.6, 0.7, 0.8],
|
||||
payload={"document_id": 2},
|
||||
),
|
||||
],
|
||||
)
|
||||
```
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
```rust
|
||||
use std::collections::HashMap;
|
||||
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder, Vector};
|
||||
|
||||
client
|
||||
.upsert_points(UpsertPointsBuilder::new(
|
||||
"documents",
|
||||
vec![
|
||||
PointStruct::new(
|
||||
1,
|
||||
HashMap::<String, Vector>::new(),
|
||||
[
|
||||
("title", "Document A".into()),
|
||||
("text", "This is document A".into()),
|
||||
],
|
||||
),
|
||||
PointStruct::new(
|
||||
2,
|
||||
HashMap::<String, Vector>::new(),
|
||||
[
|
||||
("title", "Document B".into()),
|
||||
("text", "This is document B".into()),
|
||||
],
|
||||
),
|
||||
],
|
||||
))
|
||||
.await?;
|
||||
|
||||
client
|
||||
.upsert_points(UpsertPointsBuilder::new(
|
||||
"chunks",
|
||||
vec![
|
||||
PointStruct::new(0, vec![0.1, 0.2, 0.3, 0.4], [("document_id", 1.into())]),
|
||||
PointStruct::new(1, vec![0.5, 0.6, 0.7, 0.8], [("document_id", 2.into())]),
|
||||
],
|
||||
))
|
||||
.await?;
|
||||
```
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
```typescript
|
||||
await client.upsert("documents", {
|
||||
points: [
|
||||
{
|
||||
id: 1,
|
||||
vector: {},
|
||||
payload: { title: "Document A", text: "This is document A" },
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
vector: {},
|
||||
payload: { title: "Document B", text: "This is document B" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await client.upsert("chunks", {
|
||||
points: [
|
||||
{
|
||||
id: 0,
|
||||
vector: [0.1, 0.2, 0.3, 0.4],
|
||||
payload: { document_id: 1 },
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
vector: [0.5, 0.6, 0.7, 0.8],
|
||||
payload: { document_id: 2 },
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) } // @hide
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "documents",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{}),
|
||||
Payload: qdrant.NewValueMap(map[string]any{
|
||||
"title": "Document A",
|
||||
"text": "This is document A",
|
||||
}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{}),
|
||||
Payload: qdrant.NewValueMap(map[string]any{
|
||||
"title": "Document B",
|
||||
"text": "This is document B",
|
||||
}),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "chunks",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(0),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.2, 0.3, 0.4),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"document_id": 1}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectors(0.5, 0.6, 0.7, 0.8),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"document_id": 2}),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
```http
|
||||
PUT /collections/documents/points
|
||||
{
|
||||
"points": [
|
||||
{
|
||||
"id": 1,
|
||||
"vector": {},
|
||||
"payload": {"title": "Document A", "text": "This is document A"}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"vector": {},
|
||||
"payload": {"title": "Document B", "text": "This is document B"}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
PUT /collections/chunks/points
|
||||
{
|
||||
"points": [
|
||||
{
|
||||
"id": 0,
|
||||
"vector": [0.1, 0.2, 0.3, 0.4],
|
||||
"payload": {"document_id": 1}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"vector": [0.5, 0.6, 0.7, 0.8],
|
||||
"payload": {"document_id": 2}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ValueFactory.value;
|
||||
import static io.qdrant.client.VectorsFactory.namedVectors;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
QdrantClient client = new QdrantClient(
|
||||
QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.upsertAsync(
|
||||
"documents",
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(namedVectors(Map.of()))
|
||||
.putAllPayload(Map.of(
|
||||
"title", value("Document A"),
|
||||
"text", value("This is document A")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(2))
|
||||
.setVectors(namedVectors(Map.of()))
|
||||
.putAllPayload(Map.of(
|
||||
"title", value("Document B"),
|
||||
"text", value("This is document B")))
|
||||
.build())).get();
|
||||
|
||||
client.upsertAsync(
|
||||
"chunks",
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(0))
|
||||
.setVectors(vectors(0.1f, 0.2f, 0.3f, 0.4f))
|
||||
.putAllPayload(Map.of("document_id", value(1)))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(0.5f, 0.6f, 0.7f, 0.8f))
|
||||
.putAllPayload(Map.of("document_id", value(2)))
|
||||
.build())).get();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
from qdrant_client import QdrantClient, models # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
client.upsert(
|
||||
collection_name="documents",
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector={},
|
||||
payload={"title": "Document A", "text": "This is document A"},
|
||||
),
|
||||
models.PointStruct(
|
||||
id=2,
|
||||
vector={},
|
||||
payload={"title": "Document B", "text": "This is document B"},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
client.upsert(
|
||||
collection_name="chunks",
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=0,
|
||||
vector=[0.1, 0.2, 0.3, 0.4],
|
||||
payload={"document_id": 1},
|
||||
),
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector=[0.5, 0.6, 0.7, 0.8],
|
||||
payload={"document_id": 2},
|
||||
),
|
||||
],
|
||||
)
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder, Vector};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?; // @hide
|
||||
|
||||
client
|
||||
.upsert_points(UpsertPointsBuilder::new(
|
||||
"documents",
|
||||
vec![
|
||||
PointStruct::new(
|
||||
1,
|
||||
HashMap::<String, Vector>::new(),
|
||||
[
|
||||
("title", "Document A".into()),
|
||||
("text", "This is document A".into()),
|
||||
],
|
||||
),
|
||||
PointStruct::new(
|
||||
2,
|
||||
HashMap::<String, Vector>::new(),
|
||||
[
|
||||
("title", "Document B".into()),
|
||||
("text", "This is document B".into()),
|
||||
],
|
||||
),
|
||||
],
|
||||
))
|
||||
.await?;
|
||||
|
||||
client
|
||||
.upsert_points(UpsertPointsBuilder::new(
|
||||
"chunks",
|
||||
vec![
|
||||
PointStruct::new(0, vec![0.1, 0.2, 0.3, 0.4], [("document_id", 1.into())]),
|
||||
PointStruct::new(1, vec![0.5, 0.6, 0.7, 0.8], [("document_id", 2.into())]),
|
||||
],
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
await client.upsert("documents", {
|
||||
points: [
|
||||
{
|
||||
id: 1,
|
||||
vector: {},
|
||||
payload: { title: "Document A", text: "This is document A" },
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
vector: {},
|
||||
payload: { title: "Document B", text: "This is document B" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await client.upsert("chunks", {
|
||||
points: [
|
||||
{
|
||||
id: 0,
|
||||
vector: [0.1, 0.2, 0.3, 0.4],
|
||||
payload: { document_id: 1 },
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
vector: [0.5, 0.6, 0.7, 0.8],
|
||||
payload: { document_id: 2 },
|
||||
},
|
||||
],
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
Create the two collections used by the `with_lookup` pattern. The `chunks` collection holds one point per chunk with its own vector. The `documents` collection holds one point per document and carries only payload, no vectors. A payload index on `document_id` is required for `group_by` to work on that field.
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "chunks",
|
||||
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
|
||||
);
|
||||
|
||||
await client.CreatePayloadIndexAsync(
|
||||
collectionName: "chunks",
|
||||
fieldName: "document_id",
|
||||
schemaType: PayloadSchemaType.Integer
|
||||
);
|
||||
|
||||
// No vectors, payload only.
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "documents",
|
||||
vectorsConfig: new VectorParamsMap()
|
||||
);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "chunks",
|
||||
vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Cosine }
|
||||
);
|
||||
|
||||
await client.CreatePayloadIndexAsync(
|
||||
collectionName: "chunks",
|
||||
fieldName: "document_id",
|
||||
schemaType: PayloadSchemaType.Integer
|
||||
);
|
||||
|
||||
// No vectors, payload only.
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "documents",
|
||||
vectorsConfig: new VectorParamsMap()
|
||||
);
|
||||
```
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "chunks",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 4,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
})
|
||||
|
||||
client.CreateFieldIndex(context.Background(), &qdrant.CreateFieldIndexCollection{
|
||||
CollectionName: "chunks",
|
||||
FieldName: "document_id",
|
||||
FieldType: qdrant.FieldType_FieldTypeInteger.Enum(),
|
||||
})
|
||||
|
||||
// No vectors, payload only.
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "documents",
|
||||
VectorsConfig: qdrant.NewVectorsConfigMap(
|
||||
map[string]*qdrant.VectorParams{},
|
||||
),
|
||||
})
|
||||
```
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
```java
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Collections.CreateCollection;
|
||||
import io.qdrant.client.grpc.Collections.Distance;
|
||||
import io.qdrant.client.grpc.Collections.PayloadSchemaType;
|
||||
import io.qdrant.client.grpc.Collections.VectorParams;
|
||||
import io.qdrant.client.grpc.Collections.VectorParamsMap;
|
||||
import io.qdrant.client.grpc.Collections.VectorsConfig;
|
||||
|
||||
QdrantClient client = new QdrantClient(
|
||||
QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.createCollectionAsync("chunks",
|
||||
VectorParams.newBuilder().setDistance(Distance.Cosine).setSize(4).build()).get();
|
||||
|
||||
client.createPayloadIndexAsync(
|
||||
"chunks",
|
||||
"document_id",
|
||||
PayloadSchemaType.Integer,
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
null).get();
|
||||
|
||||
// No vectors, payload only.
|
||||
client.createCollectionAsync(
|
||||
CreateCollection.newBuilder()
|
||||
.setCollectionName("documents")
|
||||
.setVectorsConfig(VectorsConfig.newBuilder()
|
||||
.setParamsMap(VectorParamsMap.newBuilder().build())
|
||||
.build())
|
||||
.build()).get();
|
||||
```
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
```python
|
||||
client.create_collection(
|
||||
collection_name="chunks",
|
||||
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
|
||||
)
|
||||
|
||||
client.create_payload_index(
|
||||
collection_name="chunks",
|
||||
field_name="document_id",
|
||||
field_schema=models.PayloadSchemaType.INTEGER,
|
||||
)
|
||||
|
||||
client.create_collection(
|
||||
collection_name="documents",
|
||||
vectors_config={}, # no vectors, payload only
|
||||
)
|
||||
```
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
```rust
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{
|
||||
CreateCollectionBuilder, CreateFieldIndexCollectionBuilder, Distance, FieldType,
|
||||
VectorParamsBuilder, VectorsConfigBuilder,
|
||||
};
|
||||
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("chunks")
|
||||
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
client
|
||||
.create_field_index(
|
||||
CreateFieldIndexCollectionBuilder::new("chunks", "document_id", FieldType::Integer)
|
||||
.wait(true),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// No vectors, payload only.
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("documents")
|
||||
.vectors_config(VectorsConfigBuilder::default()),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
```typescript
|
||||
await client.createCollection("chunks", {
|
||||
vectors: { size: 4, distance: "Cosine" },
|
||||
});
|
||||
|
||||
await client.createPayloadIndex("chunks", {
|
||||
field_name: "document_id",
|
||||
field_schema: "integer",
|
||||
});
|
||||
|
||||
await client.createCollection("documents", {
|
||||
vectors: {}, // no vectors, payload only
|
||||
});
|
||||
```
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) } // @hide
|
||||
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "chunks",
|
||||
VectorsConfig: qdrant.NewVectorsConfig(&qdrant.VectorParams{
|
||||
Size: 4,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
}),
|
||||
})
|
||||
|
||||
client.CreateFieldIndex(context.Background(), &qdrant.CreateFieldIndexCollection{
|
||||
CollectionName: "chunks",
|
||||
FieldName: "document_id",
|
||||
FieldType: qdrant.FieldType_FieldTypeInteger.Enum(),
|
||||
})
|
||||
|
||||
// No vectors, payload only.
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "documents",
|
||||
VectorsConfig: qdrant.NewVectorsConfigMap(
|
||||
map[string]*qdrant.VectorParams{},
|
||||
),
|
||||
})
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
```http
|
||||
PUT /collections/chunks
|
||||
{
|
||||
"vectors": {
|
||||
"size": 4,
|
||||
"distance": "Cosine"
|
||||
}
|
||||
}
|
||||
|
||||
PUT /collections/chunks/index
|
||||
{
|
||||
"field_name": "document_id",
|
||||
"field_schema": "integer"
|
||||
}
|
||||
|
||||
PUT /collections/documents
|
||||
{
|
||||
"vectors": {}
|
||||
}
|
||||
```
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Collections.CreateCollection;
|
||||
import io.qdrant.client.grpc.Collections.Distance;
|
||||
import io.qdrant.client.grpc.Collections.PayloadSchemaType;
|
||||
import io.qdrant.client.grpc.Collections.VectorParams;
|
||||
import io.qdrant.client.grpc.Collections.VectorParamsMap;
|
||||
import io.qdrant.client.grpc.Collections.VectorsConfig;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
QdrantClient client = new QdrantClient(
|
||||
QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.createCollectionAsync("chunks",
|
||||
VectorParams.newBuilder().setDistance(Distance.Cosine).setSize(4).build()).get();
|
||||
|
||||
client.createPayloadIndexAsync(
|
||||
"chunks",
|
||||
"document_id",
|
||||
PayloadSchemaType.Integer,
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
null).get();
|
||||
|
||||
// No vectors, payload only.
|
||||
client.createCollectionAsync(
|
||||
CreateCollection.newBuilder()
|
||||
.setCollectionName("documents")
|
||||
.setVectorsConfig(VectorsConfig.newBuilder()
|
||||
.setParamsMap(VectorParamsMap.newBuilder().build())
|
||||
.build())
|
||||
.build()).get();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
from qdrant_client import QdrantClient, models # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
client.create_collection(
|
||||
collection_name="chunks",
|
||||
vectors_config=models.VectorParams(size=4, distance=models.Distance.COSINE),
|
||||
)
|
||||
|
||||
client.create_payload_index(
|
||||
collection_name="chunks",
|
||||
field_name="document_id",
|
||||
field_schema=models.PayloadSchemaType.INTEGER,
|
||||
)
|
||||
|
||||
client.create_collection(
|
||||
collection_name="documents",
|
||||
vectors_config={}, # no vectors, payload only
|
||||
)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{
|
||||
CreateCollectionBuilder, CreateFieldIndexCollectionBuilder, Distance, FieldType,
|
||||
VectorParamsBuilder, VectorsConfigBuilder,
|
||||
};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?; // @hide
|
||||
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("chunks")
|
||||
.vectors_config(VectorParamsBuilder::new(4, Distance::Cosine)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
client
|
||||
.create_field_index(
|
||||
CreateFieldIndexCollectionBuilder::new("chunks", "document_id", FieldType::Integer)
|
||||
.wait(true),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// No vectors, payload only.
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("documents")
|
||||
.vectors_config(VectorsConfigBuilder::default()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
await client.createCollection("chunks", {
|
||||
vectors: { size: 4, distance: "Cosine" },
|
||||
});
|
||||
|
||||
await client.createPayloadIndex("chunks", {
|
||||
field_name: "document_id",
|
||||
field_schema: "integer",
|
||||
});
|
||||
|
||||
await client.createCollection("documents", {
|
||||
vectors: {}, // no vectors, payload only
|
||||
});
|
||||
+3
-3
@@ -7,10 +7,10 @@ public class Snippet
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.SearchGroupsAsync(
|
||||
collectionName: "{collection_name}",
|
||||
vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f},
|
||||
await client.QueryGroupsAsync(
|
||||
collectionName: "chunks",
|
||||
groupBy: "document_id",
|
||||
query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f },
|
||||
limit: 2,
|
||||
groupSize: 2,
|
||||
withLookup: new WithLookup
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@ using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.SearchGroupsAsync(
|
||||
collectionName: "{collection_name}",
|
||||
vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f},
|
||||
await client.QueryGroupsAsync(
|
||||
collectionName: "chunks",
|
||||
groupBy: "document_id",
|
||||
query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f },
|
||||
limit: 2,
|
||||
groupSize: 2,
|
||||
withLookup: new WithLookup
|
||||
|
||||
+2
-1
@@ -11,9 +11,10 @@ client, err := qdrant.NewClient(&qdrant.Config{
|
||||
})
|
||||
|
||||
client.QueryGroups(context.Background(), &qdrant.QueryPointGroups{
|
||||
CollectionName: "{collection_name}",
|
||||
CollectionName: "chunks",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
GroupBy: "document_id",
|
||||
Limit: qdrant.PtrOf(uint64(2)),
|
||||
GroupSize: qdrant.PtrOf(uint64(2)),
|
||||
WithLookup: &qdrant.WithLookup{
|
||||
Collection: "documents",
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
client.queryGroupsAsync(
|
||||
QueryPointGroups.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setCollectionName("chunks")
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setGroupBy("document_id")
|
||||
.setLimit(2)
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
client.query_points_groups(
|
||||
collection_name="chunks",
|
||||
# Same as in the regular search() API
|
||||
query=[1.1],
|
||||
query=[0.2, 0.1, 0.9, 0.7],
|
||||
# Grouping parameters
|
||||
group_by="document_id", # Path of the field to group by
|
||||
limit=2, # Max amount of groups
|
||||
@@ -15,7 +15,7 @@ client.query_points_groups(
|
||||
# of the looked up point, True by default
|
||||
with_payload=["title", "text"],
|
||||
# Options for specifying what to bring from the vector(s)
|
||||
# of the looked up point, True by default
|
||||
# of the looked up point, False by default
|
||||
with_vectors=False,
|
||||
),
|
||||
)
|
||||
|
||||
+2
-2
@@ -3,10 +3,10 @@ use qdrant_client::qdrant::{with_payload_selector::SelectorOptions, QueryPointGr
|
||||
|
||||
client
|
||||
.query_groups(
|
||||
QueryPointGroupsBuilder::new("{collection_name}", "document_id")
|
||||
QueryPointGroupsBuilder::new("chunks", "document_id")
|
||||
.query(vec![0.2, 0.1, 0.9, 0.7])
|
||||
.limit(2u64)
|
||||
.limit(2u64)
|
||||
.group_size(2u64)
|
||||
.with_lookup(
|
||||
WithLookupBuilder::new("documents")
|
||||
.with_payload(SelectorOptions::Include(
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
```typescript
|
||||
client.queryGroups("{collection_name}", {
|
||||
query: [1.1],
|
||||
client.queryGroups("chunks", {
|
||||
query: [0.2, 0.1, 0.9, 0.7],
|
||||
group_by: "document_id",
|
||||
limit: 2,
|
||||
group_size: 2,
|
||||
|
||||
+2
-1
@@ -15,9 +15,10 @@ func Main() {
|
||||
if err != nil { panic(err) } // @hide
|
||||
|
||||
client.QueryGroups(context.Background(), &qdrant.QueryPointGroups{
|
||||
CollectionName: "{collection_name}",
|
||||
CollectionName: "chunks",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
GroupBy: "document_id",
|
||||
Limit: qdrant.PtrOf(uint64(2)),
|
||||
GroupSize: qdrant.PtrOf(uint64(2)),
|
||||
WithLookup: &qdrant.WithLookup{
|
||||
Collection: "documents",
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
POST /collections/chunks/points/query/groups
|
||||
{
|
||||
// Same as in the regular query API
|
||||
"query": [1.1],
|
||||
"query": [0.2, 0.1, 0.9, 0.7],
|
||||
|
||||
// Grouping parameters
|
||||
"group_by": "document_id",
|
||||
@@ -19,7 +19,7 @@ POST /collections/chunks/points/query/groups
|
||||
"with_payload": ["title", "text"],
|
||||
|
||||
// Options for specifying what to bring from the vector(s)
|
||||
// of the looked up point, true by default
|
||||
// of the looked up point, false by default
|
||||
"with_vectors": false
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class Snippet {
|
||||
|
||||
client.queryGroupsAsync(
|
||||
QueryPointGroups.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setCollectionName("chunks")
|
||||
.setQuery(nearest(0.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setGroupBy("document_id")
|
||||
.setLimit(2)
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
client.query_points_groups(
|
||||
collection_name="chunks",
|
||||
# Same as in the regular search() API
|
||||
query=[1.1],
|
||||
query=[0.2, 0.1, 0.9, 0.7],
|
||||
# Grouping parameters
|
||||
group_by="document_id", # Path of the field to group by
|
||||
limit=2, # Max amount of groups
|
||||
@@ -18,7 +18,7 @@ client.query_points_groups(
|
||||
# of the looked up point, True by default
|
||||
with_payload=["title", "text"],
|
||||
# Options for specifying what to bring from the vector(s)
|
||||
# of the looked up point, True by default
|
||||
# of the looked up point, False by default
|
||||
with_vectors=False,
|
||||
),
|
||||
)
|
||||
|
||||
+2
-2
@@ -5,10 +5,10 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
|
||||
client
|
||||
.query_groups(
|
||||
QueryPointGroupsBuilder::new("{collection_name}", "document_id")
|
||||
QueryPointGroupsBuilder::new("chunks", "document_id")
|
||||
.query(vec![0.2, 0.1, 0.9, 0.7])
|
||||
.limit(2u64)
|
||||
.limit(2u64)
|
||||
.group_size(2u64)
|
||||
.with_lookup(
|
||||
WithLookupBuilder::new("documents")
|
||||
.with_payload(SelectorOptions::Include(
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
client.queryGroups("{collection_name}", {
|
||||
query: [1.1],
|
||||
client.queryGroups("chunks", {
|
||||
query: [0.2, 0.1, 0.9, 0.7],
|
||||
group_by: "document_id",
|
||||
limit: 2,
|
||||
group_size: 2,
|
||||
|
||||
Reference in New Issue
Block a user