Add worked with_lookup example

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dylan Couzon
2026-05-19 19:08:36 -04:00
co-authored by Claude Opus 4.7
parent 2b97750ade
commit a6104d7b7a
42 changed files with 960 additions and 37 deletions
@@ -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`.
@@ -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 },
},
}
);
}
}
@@ -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 },
},
}
);
```
@@ -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}),
},
},
})
```
@@ -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();
```
@@ -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},
),
],
)
```
@@ -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?;
```
@@ -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 },
},
],
});
```
@@ -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}),
},
},
})
}
@@ -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}
}
]
}
```
@@ -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();
}
}
@@ -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},
),
],
)
@@ -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(())
}
@@ -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 },
},
],
});