mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-25 22:18:30 +02:00
Automated snippet conversion by scripts
These changes are purely mechanical to differentiate them from manual fixes/adjustments made in the next commit. This results in broken code as some snippets contain errors. Made in four steps: 1. Run ./migrate-snippet.py that converts `.md` files to code files and perhaps adds missing lines under `// @hide` comments. 2. Sort Java imports. 3. Remove old `.md` files. 4. Run ./generate.md to produce `*/generated/*.md` files.
This commit is contained in:
+3
-4
@@ -1,7 +1,4 @@
|
||||
```java
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ValueFactory.value;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
@@ -10,7 +7,6 @@ import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import io.qdrant.client.grpc.Points.PointVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsIdsList;
|
||||
import io.qdrant.client.grpc.Points.PointsSelector;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.ClearPayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeletePayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeletePoints;
|
||||
@@ -18,7 +14,10 @@ import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeleteVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.PointStructList;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.SetPayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.UpdateVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation;
|
||||
import io.qdrant.client.grpc.Points.VectorsSelector;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
client
|
||||
.batchUpdateAsync(
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
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.vectors;
|
||||
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import io.qdrant.client.grpc.Points.PointVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsIdsList;
|
||||
import io.qdrant.client.grpc.Points.PointsSelector;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.ClearPayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeletePayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeletePoints;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.DeleteVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.PointStructList;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.SetPayload;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation.UpdateVectors;
|
||||
import io.qdrant.client.grpc.Points.PointsUpdateOperation;
|
||||
import io.qdrant.client.grpc.Points.VectorsSelector;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
client
|
||||
.batchUpdateAsync(
|
||||
"{collection_name}",
|
||||
List.of(
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setUpsert(
|
||||
PointStructList.newBuilder()
|
||||
.addPoints(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(1.0f, 2.0f, 3.0f, 4.0f))
|
||||
.build())
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setUpdateVectors(
|
||||
UpdateVectors.newBuilder()
|
||||
.addPoints(
|
||||
PointVectors.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(1.0f, 2.0f, 3.0f, 4.0f))
|
||||
.build())
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setDeleteVectors(
|
||||
DeleteVectors.newBuilder()
|
||||
.setPointsSelector(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.setVectors(VectorsSelector.newBuilder().addNames("").build())
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setOverwritePayload(
|
||||
SetPayload.newBuilder()
|
||||
.setPointsSelector(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.putAllPayload(Map.of("test_payload", value(1)))
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setSetPayload(
|
||||
SetPayload.newBuilder()
|
||||
.setPointsSelector(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.putAllPayload(
|
||||
Map.of("test_payload_2", value(2), "test_payload_3", value(3)))
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setDeletePayload(
|
||||
DeletePayload.newBuilder()
|
||||
.setPointsSelector(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.addKeys("test_payload_2")
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setClearPayload(
|
||||
ClearPayload.newBuilder()
|
||||
.setPoints(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.build())
|
||||
.build(),
|
||||
PointsUpdateOperation.newBuilder()
|
||||
.setDeletePoints(
|
||||
DeletePoints.newBuilder()
|
||||
.setPoints(
|
||||
PointsSelector.newBuilder()
|
||||
.setPoints(PointsIdsList.newBuilder().addIds(id(1)).build())
|
||||
.build())
|
||||
.build())
|
||||
.build()))
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
from qdrant_client import QdrantClient, models # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
client.batch_update_points(
|
||||
collection_name="{collection_name}",
|
||||
update_operations=[
|
||||
models.UpsertOperation(
|
||||
upsert=models.PointsList(
|
||||
points=[
|
||||
models.PointStruct(
|
||||
id=1,
|
||||
vector=[1.0, 2.0, 3.0, 4.0],
|
||||
payload={},
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
models.UpdateVectorsOperation(
|
||||
update_vectors=models.UpdateVectors(
|
||||
points=[
|
||||
models.PointVectors(
|
||||
id=1,
|
||||
vector=[1.0, 2.0, 3.0, 4.0],
|
||||
)
|
||||
]
|
||||
)
|
||||
),
|
||||
models.DeleteVectorsOperation(
|
||||
delete_vectors=models.DeleteVectors(points=[1], vector=[""])
|
||||
),
|
||||
models.OverwritePayloadOperation(
|
||||
overwrite_payload=models.SetPayload(
|
||||
payload={"test_payload": 1},
|
||||
points=[1],
|
||||
)
|
||||
),
|
||||
models.SetPayloadOperation(
|
||||
set_payload=models.SetPayload(
|
||||
payload={
|
||||
"test_payload_2": 2,
|
||||
"test_payload_3": 3,
|
||||
},
|
||||
points=[1],
|
||||
)
|
||||
),
|
||||
models.DeletePayloadOperation(
|
||||
delete_payload=models.DeletePayload(keys=["test_payload_2"], points=[1])
|
||||
),
|
||||
models.ClearPayloadOperation(clear_payload=models.PointIdsList(points=[1])),
|
||||
models.DeleteOperation(delete=models.PointIdsList(points=[1])),
|
||||
],
|
||||
)
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use qdrant_client::qdrant::{
|
||||
points_update_operation::{
|
||||
ClearPayload, DeletePayload, DeletePoints, DeleteVectors, Operation, OverwritePayload,
|
||||
PointStructList, SetPayload, UpdateVectors,
|
||||
},
|
||||
PointStruct, PointVectors, PointsUpdateOperation, UpdateBatchPointsBuilder, VectorsSelector,
|
||||
};
|
||||
use qdrant_client::Payload;
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
client
|
||||
.update_points_batch(
|
||||
UpdateBatchPointsBuilder::new(
|
||||
"{collection_name}",
|
||||
vec![
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::Upsert(PointStructList {
|
||||
points: vec![PointStruct::new(
|
||||
1,
|
||||
vec![1.0, 2.0, 3.0, 4.0],
|
||||
Payload::default(),
|
||||
)],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::UpdateVectors(UpdateVectors {
|
||||
points: vec![PointVectors {
|
||||
id: Some(1.into()),
|
||||
vectors: Some(vec![1.0, 2.0, 3.0, 4.0].into()),
|
||||
}],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::DeleteVectors(DeleteVectors {
|
||||
points_selector: Some(vec![1.into()].into()),
|
||||
vectors: Some(VectorsSelector {
|
||||
names: vec!["".into()],
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::OverwritePayload(OverwritePayload {
|
||||
points_selector: Some(vec![1.into()].into()),
|
||||
payload: HashMap::from([("test_payload".to_string(), 1.into())]),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::SetPayload(SetPayload {
|
||||
points_selector: Some(vec![1.into()].into()),
|
||||
payload: HashMap::from([
|
||||
("test_payload_2".to_string(), 2.into()),
|
||||
("test_payload_3".to_string(), 3.into()),
|
||||
]),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::DeletePayload(DeletePayload {
|
||||
points_selector: Some(vec![1.into()].into()),
|
||||
keys: vec!["test_payload_2".to_string()],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::ClearPayload(ClearPayload {
|
||||
points: Some(vec![1.into()].into()),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::DeletePoints(DeletePoints {
|
||||
points: Some(vec![1.into()].into()),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
],
|
||||
)
|
||||
.wait(true),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
client.batchUpdate("{collection_name}", {
|
||||
operations: [
|
||||
{
|
||||
upsert: {
|
||||
points: [
|
||||
{
|
||||
id: 1,
|
||||
vector: [1.0, 2.0, 3.0, 4.0],
|
||||
payload: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
update_vectors: {
|
||||
points: [
|
||||
{
|
||||
id: 1,
|
||||
vector: [1.0, 2.0, 3.0, 4.0],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
delete_vectors: {
|
||||
points: [1],
|
||||
vector: [""],
|
||||
},
|
||||
},
|
||||
{
|
||||
overwrite_payload: {
|
||||
payload: {
|
||||
test_payload: 1,
|
||||
},
|
||||
points: [1],
|
||||
},
|
||||
},
|
||||
{
|
||||
set_payload: {
|
||||
payload: {
|
||||
test_payload_2: 2,
|
||||
test_payload_3: 3,
|
||||
},
|
||||
points: [1],
|
||||
},
|
||||
},
|
||||
{
|
||||
delete_payload: {
|
||||
keys: ["test_payload_2"],
|
||||
points: [1],
|
||||
},
|
||||
},
|
||||
{
|
||||
clear_payload: {
|
||||
points: [1],
|
||||
},
|
||||
},
|
||||
{
|
||||
delete: {
|
||||
points: [1],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
curl -X GET http://localhost:6333/collections/{collection_name}/exists
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
await client.CollectionExistsAsync("{collection_name}");
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package snippet
|
||||
|
||||
import "context"
|
||||
|
||||
func Main() {
|
||||
client.CollectionExists(context.Background(), "my_collection")
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
client.collectionExistsAsync("{collection_name}").get();
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
from qdrant_client import QdrantClient # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
client.collection_exists(collection_name="{collection_name}")
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
client.collection_exists("{collection_name}").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
client.collectionExists("{collection_name}");
|
||||
@@ -0,0 +1,11 @@
|
||||
using Qdrant.Client;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.ClearPayloadAsync(collectionName: "{collection_name}", ids: new ulong[] { 0, 3, 100 });
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
client
|
||||
.clearPayloadAsync("{collection_name}", List.of(id(0), id(3), id(100)), true, null, null)
|
||||
.get();
|
||||
@@ -0,0 +1,16 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client.ClearPayload(context.Background(), &qdrant.ClearPayloadPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Points: qdrant.NewPointsSelector(
|
||||
qdrant.NewIDNum(0),
|
||||
qdrant.NewIDNum(3)),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
client
|
||||
.clearPayloadAsync("{collection_name}", List.of(id(0), id(3), id(100)), true, null, null)
|
||||
.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
from qdrant_client import QdrantClient # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
client.clear_payload(
|
||||
collection_name="{collection_name}",
|
||||
points_selector=[0, 3, 100],
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
use qdrant_client::qdrant::{ClearPayloadPointsBuilder, PointsIdsList};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
client
|
||||
.clear_payload(
|
||||
ClearPayloadPointsBuilder::new("{collection_name}")
|
||||
.points(PointsIdsList {
|
||||
ids: vec![0.into(), 3.into(), 10.into()],
|
||||
})
|
||||
.wait(true),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
client.clearPayload("{collection_name}", {
|
||||
points: [0, 3, 100],
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
# Create a new vector
|
||||
curl -X PUT "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points?wait=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"points": [
|
||||
{
|
||||
"id": 1,
|
||||
"vector": {
|
||||
"image": "https://qdrant.tech/example.png",
|
||||
"model": "qdrant/clip-vit-b-32-vision"
|
||||
},
|
||||
"payload": {
|
||||
"title": "Example Image"
|
||||
}
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
# Perform a search query
|
||||
curl -X POST "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points/query" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"query": {
|
||||
"text": "Mission to Mars",
|
||||
"model": "qdrant/clip-vit-b-32-text"
|
||||
}
|
||||
}'
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
using Value = Qdrant.Client.Grpc.Value;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient(
|
||||
host: "xyz-example.qdrant.io",
|
||||
port: 6334,
|
||||
https: true,
|
||||
apiKey: "<paste-your-api-key-here>"
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "<your-collection>",
|
||||
points: new List <PointStruct> {
|
||||
new() {
|
||||
Id = 1,
|
||||
Vectors = new Image() {
|
||||
Image_ = "https://qdrant.tech/example.png",
|
||||
Model = "qdrant/clip-vit-b-32-vision",
|
||||
},
|
||||
Payload = {
|
||||
["title"] = "Example Image"
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
var points = await client.QueryAsync(
|
||||
collectionName: "<your-collection>",
|
||||
query: new Document() {
|
||||
Text = "Mission to Mars",
|
||||
Model = "qdrant/clip-vit-b-32-text"
|
||||
}
|
||||
);
|
||||
|
||||
foreach(var point in points) {
|
||||
Console.WriteLine(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
from qdrant_client import QdrantClient
|
||||
from qdrant_client.models import PointStruct, Image, Document
|
||||
|
||||
client = QdrantClient(
|
||||
url="https://xyz-example.qdrant.io:6333",
|
||||
api_key="<paste-your-api-key-here>",
|
||||
# IMPORTANT
|
||||
# If not enabled, inference will be performed locally
|
||||
cloud_inference=True,
|
||||
)
|
||||
|
||||
points = [
|
||||
PointStruct(
|
||||
id=1,
|
||||
vector=Image(
|
||||
image="https://qdrant.tech/example.png",
|
||||
model="qdrant/clip-vit-b-32-vision"
|
||||
),
|
||||
payload={
|
||||
"title": "Example Image"
|
||||
}
|
||||
)
|
||||
]
|
||||
|
||||
client.upsert(collection_name="<your-collection>", points=points)
|
||||
|
||||
result = client.query_points(
|
||||
collection_name="<your-collection>",
|
||||
query=Document(
|
||||
text="Mission to Mars",
|
||||
model="qdrant/clip-vit-b-32-text"
|
||||
)
|
||||
)
|
||||
|
||||
print(result)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import {QdrantClient} from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({
|
||||
url: 'https://xyz-example.qdrant.io:6333',
|
||||
apiKey: '<paste-your-api-key-here>',
|
||||
});
|
||||
|
||||
const points = [
|
||||
{
|
||||
id: 1,
|
||||
vector: {
|
||||
image: "https://qdrant.tech/example.png",
|
||||
model: "qdrant/clip-vit-b-32-vision"
|
||||
},
|
||||
payload: {
|
||||
title: "Example Image"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
await client.upsert("<your-collection>", { wait: true, points });
|
||||
|
||||
const result = await client.query(
|
||||
"<your-collection>",
|
||||
{
|
||||
query: {
|
||||
text: "Mission to Mars",
|
||||
model: "qdrant/clip-vit-b-32-text"
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
console.log(result);
|
||||
@@ -0,0 +1,27 @@
|
||||
# Create a new vector
|
||||
curl -X PUT "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points?wait=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"points": [
|
||||
{
|
||||
"id": 1,
|
||||
"payload": { "topic": "cooking", "type": "dessert" },
|
||||
"vector": {
|
||||
"text": "Recipe for baking chocolate chip cookies",
|
||||
"model": "<the-model-to-use>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
# Perform a search query
|
||||
curl -X POST "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points/query" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"query": {
|
||||
"text": "How to bake cookies?",
|
||||
"model": "<the-model-to-use>"
|
||||
}
|
||||
}'
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
using Value = Qdrant.Client.Grpc.Value;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient(
|
||||
host: "xyz-example.qdrant.io",
|
||||
port: 6334,
|
||||
https: true,
|
||||
apiKey: "<paste-your-api-key-here>"
|
||||
);
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "<your-collection>",
|
||||
points: new List <PointStruct> {
|
||||
new() {
|
||||
Id = 1,
|
||||
Vectors = new Document() {
|
||||
Text = "Recipe for baking chocolate chip cookies",
|
||||
Model = "<the-model-to-use>",
|
||||
},
|
||||
Payload = {
|
||||
["topic"] = "cooking",
|
||||
["type"] = "dessert"
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
var points = await client.QueryAsync(
|
||||
collectionName: "<your-collection>",
|
||||
query: new Document() {
|
||||
Text = "How to bake cookies?",
|
||||
Model = "<the-model-to-use>"
|
||||
}
|
||||
);
|
||||
|
||||
foreach(var point in points) {
|
||||
Console.WriteLine(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
from qdrant_client import QdrantClient
|
||||
from qdrant_client.models import PointStruct, Document
|
||||
|
||||
client = QdrantClient(
|
||||
url="https://xyz-example.qdrant.io:6333",
|
||||
api_key="<paste-your-api-key-here>",
|
||||
# IMPORTANT
|
||||
# If not enabled, inference will be performed locally
|
||||
cloud_inference=True,
|
||||
)
|
||||
|
||||
points = [
|
||||
PointStruct(
|
||||
id=1,
|
||||
payload={"topic": "cooking", "type": "dessert"},
|
||||
vector=Document(
|
||||
text="Recipe for baking chocolate chip cookies",
|
||||
model="<the-model-to-use>"
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
client.upsert(collection_name="<your-collection>", points=points)
|
||||
|
||||
result = client.query_points(
|
||||
collection_name="<your-collection>",
|
||||
query=Document(
|
||||
text="How to bake cookies?",
|
||||
model="<the-model-to-use>"
|
||||
)
|
||||
)
|
||||
|
||||
print(result)
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import {QdrantClient} from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({
|
||||
url: 'https://xyz-example.qdrant.io:6333',
|
||||
apiKey: '<paste-your-api-key-here>',
|
||||
});
|
||||
|
||||
const points = [
|
||||
{
|
||||
id: 1,
|
||||
payload: { topic: "cooking", type: "dessert" },
|
||||
vector: {
|
||||
text: "Recipe for baking chocolate chip cookies",
|
||||
model: "<the-model-to-use>"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
await client.upsert("<your-collection>", { wait: true, points });
|
||||
|
||||
const result = await client.query(
|
||||
"<your-collection>",
|
||||
{
|
||||
query: {
|
||||
text: "How to bake cookies?",
|
||||
model: "<the-model-to-use>"
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
console.log(result);
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "{collection_name}",
|
||||
vectorsConfig: new VectorParamsMap
|
||||
{
|
||||
Map = {
|
||||
["dense_vector"] = new VectorParams {
|
||||
Size = 384, Distance = Distance.Cosine
|
||||
},
|
||||
}
|
||||
},
|
||||
sparseVectorsConfig: new SparseVectorConfig
|
||||
{
|
||||
Map = {
|
||||
["bm25_sparse_vector"] = new() {
|
||||
Modifier = Modifier.Idf, // Enable Inverse Document Frequency
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
```python
|
||||
from qdrant_client import models
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client.create_collection(
|
||||
collection_name="{collection_name}",
|
||||
@@ -15,4 +15,4 @@ client.create_collection(
|
||||
)
|
||||
}
|
||||
)
|
||||
```
|
||||
```
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package snippet
|
||||
|
||||
|
||||
|
||||
func Main() {
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "{collection_name}",
|
||||
VectorsConfig: qdrant.NewVectorsConfigMap(
|
||||
map[string]*qdrant.VectorParams{
|
||||
"dense_vector": {
|
||||
Size: 384,
|
||||
Distance: qdrant.Distance_Cosine,
|
||||
},
|
||||
}),
|
||||
SparseVectorsConfig: qdrant.NewSparseVectorsConfig(
|
||||
map[string]*qdrant.SparseVectorParams{
|
||||
"bm25_sparse_vector": {
|
||||
Modifier: qdrant.Modifier_Idf.Enum(),
|
||||
},
|
||||
},
|
||||
),
|
||||
})
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import io.qdrant.client.grpc.Collections.CreateCollection;
|
||||
import io.qdrant.client.grpc.Collections.Distance;
|
||||
import io.qdrant.client.grpc.Collections.Modifier;
|
||||
import io.qdrant.client.grpc.Collections.SparseVectorConfig;
|
||||
import io.qdrant.client.grpc.Collections.SparseVectorParams;
|
||||
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 {
|
||||
client
|
||||
.createCollectionAsync(
|
||||
CreateCollection.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setVectorsConfig(
|
||||
VectorsConfig.newBuilder()
|
||||
.setParamsMap(
|
||||
VectorParamsMap.newBuilder()
|
||||
.putAllMap(
|
||||
Map.of(
|
||||
"dense_vector",
|
||||
VectorParams.newBuilder()
|
||||
.setSize(384)
|
||||
.setDistance(Distance.Cosine)
|
||||
.build())))
|
||||
.setSparseVectorsConfig(
|
||||
SparseVectorConfig.newBuilder()
|
||||
.putMap(
|
||||
"bm25_sparse_vector",
|
||||
SparseVectorParams.newBuilder()
|
||||
.setModifier(Modifier.Idf)
|
||||
.build())))
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client.create_collection(
|
||||
collection_name="{collection_name}",
|
||||
vectors_config={
|
||||
"dense_vector": models.VectorParams(
|
||||
size=384,
|
||||
distance=models.Distance.COSINE
|
||||
)
|
||||
},
|
||||
sparse_vectors_config={
|
||||
"bm25_sparse_vector": models.SparseVectorParams(
|
||||
modifier=models.Modifier.IDF # Enable Inverse Document Frequency
|
||||
)
|
||||
}
|
||||
)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use qdrant_client::qdrant::{
|
||||
CreateCollectionBuilder, Distance, Modifier, SparseVectorParamsBuilder,
|
||||
SparseVectorsConfigBuilder, VectorParamsBuilder, VectorsConfigBuilder,
|
||||
};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let mut vector_config = VectorsConfigBuilder::default();
|
||||
vector_config.add_named_vector_params(
|
||||
"dense_vector",
|
||||
VectorParamsBuilder::new(384, Distance::Cosine),
|
||||
);
|
||||
|
||||
let mut sparse_vectors_config = SparseVectorsConfigBuilder::default();
|
||||
sparse_vectors_config.add_named_vector_params(
|
||||
"bm25_sparse_vector",
|
||||
SparseVectorParamsBuilder::default().modifier(Modifier::Idf), // Enable Inverse Document Frequency
|
||||
);
|
||||
|
||||
client
|
||||
.create_collection(
|
||||
CreateCollectionBuilder::new("{collection_name}")
|
||||
.vectors_config(vector_config)
|
||||
.sparse_vectors_config(sparse_vectors_config),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
client.createCollection("{collection_name}", {
|
||||
vectors: {
|
||||
dense_vector: { size: 384, distance: "Cosine" },
|
||||
},
|
||||
sparse_vectors: {
|
||||
bm25_sparse_vector: {
|
||||
modifier: "idf" // Enable Inverse Document Frequency
|
||||
}
|
||||
}
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var queryText = "What is relapsing polychondritis?"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
```python
|
||||
query_text = "What is relapsing polychondritis?"
|
||||
```
|
||||
```
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package snippet
|
||||
|
||||
|
||||
|
||||
func Main() {
|
||||
queryText := "What is relapsing polychondritis?"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
String queryText = "What is relapsing polychondritis?";
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
query_text = "What is relapsing polychondritis?"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let query_text = "What is relapsing polychondritis?";
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
let query_text = "What is relapsing polychondritis?";
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using Qdrant.Client;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient(
|
||||
host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||
https: true,
|
||||
apiKey: "<paste-your-api-key-here>"
|
||||
);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||
Port: 6334,
|
||||
APIKey: "<paste-your-api-key-here>",
|
||||
UseTLS: true,
|
||||
})
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
QdrantClient client =
|
||||
new QdrantClient(
|
||||
QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
|
||||
.withApiKey("<paste-your-api-key-here>")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
from qdrant_client import QdrantClient
|
||||
|
||||
qdrant_client = QdrantClient(
|
||||
"xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||
api_key="<paste-your-api-key-here>",
|
||||
cloud_inference=True,
|
||||
timeout=30.0
|
||||
)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{Document};
|
||||
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = Qdrant::from_url("https://xyz-example.qdrant.io:6334")
|
||||
.api_key("<paste-your-api-key-here>")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import {QdrantClient} from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({
|
||||
url: 'https://xyz-example.qdrant.io:6333',
|
||||
apiKey: '<paste-your-api-key-here>',
|
||||
});
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}", prefetch: new List <PrefetchQuery> {
|
||||
new() {
|
||||
Query = new Document {
|
||||
Text = queryText,
|
||||
Model = bm25Model
|
||||
},
|
||||
Using = "bm25_sparse_vector",
|
||||
Limit = 5
|
||||
},
|
||||
new() {
|
||||
Query = new Document {
|
||||
Text = queryText,
|
||||
Model = denseModel
|
||||
},
|
||||
Using = "dense_vector",
|
||||
Limit = 5
|
||||
}
|
||||
},
|
||||
query: Fusion.Rrf,
|
||||
limit: 5
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -25,4 +25,4 @@ results = client.query_points(
|
||||
)
|
||||
|
||||
print(results.points)
|
||||
```
|
||||
```
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package snippet
|
||||
|
||||
|
||||
|
||||
func Main() {
|
||||
prefetch := []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Query: qdrant.NewQueryDocument(&qdrant.Document{
|
||||
Text: queryText,
|
||||
Model: bm25Model,
|
||||
}),
|
||||
Using: qdrant.PtrOf("bm25_sparse_vector"),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDocument(&qdrant.Document{
|
||||
Text: queryText,
|
||||
Model: denseModel,
|
||||
}),
|
||||
Using: qdrant.PtrOf("dense_vector"),
|
||||
},
|
||||
}
|
||||
|
||||
client.Query(ctx, &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Prefetch: prefetch,
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_RRF),
|
||||
})
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.fusion;
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
import io.qdrant.client.grpc.Points.Document;
|
||||
import io.qdrant.client.grpc.Points.Fusion;
|
||||
import io.qdrant.client.grpc.Points.PrefetchQuery;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
PrefetchQuery densePrefetch =
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(
|
||||
nearest(Document.newBuilder().setText(queryText).setModel(denseModel).build()))
|
||||
.setUsing("dense_vector")
|
||||
.build();
|
||||
|
||||
PrefetchQuery bm25Prefetch =
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(Document.newBuilder().setText(queryText).setModel(bm25Model).build()))
|
||||
.setUsing("bm25_sparse_vector")
|
||||
.build();
|
||||
|
||||
QueryPoints request =
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addPrefetch(densePrefetch)
|
||||
.addPrefetch(bm25Prefetch)
|
||||
.setQuery(fusion(Fusion.RRF))
|
||||
.build();
|
||||
|
||||
client.queryAsync(request).get();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
from qdrant_client import QdrantClient, models # @hide
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
|
||||
results = client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
prefetch=[
|
||||
models.Prefetch(
|
||||
query=Document(
|
||||
text=query_text,
|
||||
model=dense_model
|
||||
),
|
||||
using="dense_vector",
|
||||
limit=5
|
||||
),
|
||||
models.Prefetch(
|
||||
query=Document(
|
||||
text=query_text,
|
||||
model=bm25_model
|
||||
),
|
||||
using="bm25_sparse_vector",
|
||||
limit=5
|
||||
)
|
||||
],
|
||||
query=models.FusionQuery(fusion=models.Fusion.RRF),
|
||||
limit=5,
|
||||
with_payload=True
|
||||
)
|
||||
|
||||
print(results.points)
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
use qdrant_client::qdrant::{Document, Fusion, PrefetchQueryBuilder, Query, QueryPointsBuilder};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let dense_prefetch = PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(Document::new(query_text, dense_model)))
|
||||
.using("dense_vector")
|
||||
.build();
|
||||
|
||||
let bm25_prefetch = PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(Document::new(query_text, bm25_model)))
|
||||
.using("bm25_sparse_vector")
|
||||
.build();
|
||||
|
||||
let query_request = QueryPointsBuilder::new(collection_name)
|
||||
.add_prefetch(dense_prefetch)
|
||||
.add_prefetch(bm25_prefetch)
|
||||
.query(Query::new_fusion(Fusion::Rrf))
|
||||
.with_payload(true)
|
||||
.build();
|
||||
|
||||
let results = client.query(query_request).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
|
||||
const results = await client.query(collectionName, {
|
||||
prefetch: [
|
||||
{
|
||||
query: {
|
||||
text: queryText,
|
||||
model: denseModel,
|
||||
},
|
||||
using: "dense_vector",
|
||||
},
|
||||
{
|
||||
query: {
|
||||
text: queryText,
|
||||
model: bm25Model,
|
||||
},
|
||||
using: "bm25_sparse_vector",
|
||||
},
|
||||
],
|
||||
query: {
|
||||
fusion: "rrf",
|
||||
},
|
||||
});
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var denseModel = "sentence-transformers/all-minilm-l6-v2";
|
||||
var bm25Model = "qdrant/bm25";
|
||||
// NOTE: LoadDataset is a user-defined function.
|
||||
// Implement it to handle dataset loading as needed.
|
||||
var dataset = LoadDataset("miriad/miriad-4.4M", "train[0:100]");
|
||||
var points = new List<PointStruct>();
|
||||
|
||||
foreach (var item in dataset)
|
||||
{
|
||||
var passage = item["passage_text"].ToString();
|
||||
|
||||
var point = new PointStruct
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Vectors = new Dictionary<string, Vector>
|
||||
{
|
||||
["dense_vector"] = new Document
|
||||
{
|
||||
Text = passage,
|
||||
Model = denseModel
|
||||
},
|
||||
["bm25_sparse_vector"] = new Document
|
||||
{
|
||||
Text = passage,
|
||||
Model = bm25Model
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
points.Add(point);
|
||||
}
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "{collectionName}",
|
||||
points: points
|
||||
);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user