Skip to content

Commit

Permalink
add random query snippets (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: Anush  <anushshetty90@gmail.com>
  • Loading branch information
coszio and Anush008 authored Aug 16, 2024
1 parent e49d0af commit 8c19d94
Show file tree
Hide file tree
Showing 8 changed files with 1,175 additions and 1,113 deletions.
10 changes: 5 additions & 5 deletions fern/apis/master/openapi-overrides.yml

Large diffs are not rendered by default.

2,148 changes: 1,081 additions & 1,067 deletions fern/apis/v1.10.x/openapi-overrides.yml

Large diffs are not rendered by default.

74 changes: 44 additions & 30 deletions fern/apis/v1.11.x/openapi-overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1404,26 +1404,29 @@ paths:
- code: "use qdrant_client::Qdrant;\nuse qdrant_client::qdrant::{Condition,\
\ Filter, PointId, PrefetchQueryBuilder, Query, QueryPointsBuilder};\n\
\nlet client = Qdrant::from_url(\"http://localhost:6334\").build()?;\n\
\n// Query nearest by ID\nclient.query(\n QueryPointsBuilder::new(\"\
\n// Query nearest by ID\nlet _nearest = client.query(\n QueryPointsBuilder::new(\"\
{collection_name}\")\n .query(Query::new_nearest(PointId::new(\"\
43cf51e2-8777-4f52-bc74-c2cbde0c8b04\")))\n).await?;\n\n// Recommend on\
\ the average of these vectors\nclient.query(\n QueryPointsBuilder::new(\"\
{collection_name}\")\n .query(Query::new_recommend(\n \
\ RecommendInputBuilder::default()\n .add_positive(vec![0.1;\
\ the average of these vectors\nlet _recommendations = client.query(\n\
\ QueryPointsBuilder::new(\"{collection_name}\")\n .query(Query::new_recommend(\n\
\ RecommendInputBuilder::default()\n .add_positive(vec![0.1;\
\ 8])\n .add_negative(PointId::from(0))\n ))\n).await?;\n\
\n// Fusion query\nclient.query(\n QueryPointsBuilder::new(\"{collection_name}\"\
)\n .add_prefetch(PrefetchQueryBuilder::default()\n \
\ .query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))\n \
\ .using(\"sparse\")\n .limit(20u64)\n )\n \
\ .add_prefetch(PrefetchQueryBuilder::default()\n .query(Query::new_nearest(vec![0.01,\
\n// Fusion query\nlet _hybrid = client.query(\n QueryPointsBuilder::new(\"\
{collection_name}\")\n .add_prefetch(PrefetchQueryBuilder::default()\n\
\ .query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))\n\
\ .using(\"sparse\")\n .limit(20u64)\n )\n\
\ .add_prefetch(PrefetchQueryBuilder::default()\n .query(Query::new_nearest(vec![0.01,\
\ 0.45, 0.67]))\n .using(\"dense\")\n .limit(20u64)\n\
\ )\n .query(Query::new_fusion(Fusion::Rrf))\n).await?;\n\
\n// 2-stage query\nclient.query(\n QueryPointsBuilder::new(\"{collection_name}\"\
)\n .add_prefetch(PrefetchQueryBuilder::default()\n \
\ .query(Query::new_nearest(vec![0.01, 0.45, 0.67]))\n .limit(100u64)\n\
\ )\n .query(Query::new_nearest(vec![\n vec![0.1,\
\ 0.2],\n vec![0.2, 0.1],\n vec![0.8, 0.9],\n \
\ ]))\n .using(\"colbert\")\n .limit(10u64)\n).await?;\n"
\n// 2-stage query\nlet _refined = client.query(\n QueryPointsBuilder::new(\"\
{collection_name}\")\n .add_prefetch(PrefetchQueryBuilder::default()\n\
\ .query(Query::new_nearest(vec![0.01, 0.45, 0.67]))\n \
\ .limit(100u64)\n )\n .query(Query::new_nearest(vec![\n\
\ vec![0.1, 0.2],\n vec![0.2, 0.1],\n \
\ vec![0.8, 0.9],\n ]))\n .using(\"colbert\")\n \
\ .limit(10u64)\n).await?;\n\n// Random sampling (as of 1.11.0)\nlet _sampled\
\ = client\n .query(\n QueryPointsBuilder::new(\"{collection_name}\"\
)\n .query(Query::new_sample(Sample::Random))\n )\n .await?;\n"
language: rust
- code-samples:
- code: "using Qdrant.Client;\nusing Qdrant.Client.Grpc;\n\nvar client = new\
Expand All @@ -1445,7 +1448,9 @@ paths:
\ new List<PrefetchQuery>\n\t{\n\t\tnew() { Query = new float[] { 0.01f,\
\ 0.45f, 0.67f }, Limit = 100 }\n\t},\n\tquery: new float[][] { [0.1f,\
\ 0.2f], [0.2f, 0.1f], [0.8f, 0.9f] },\n\tusingVector: \"colbert\",\n\t\
limit: 10\n);\n"
limit: 10\n);\n\n// Random sampling (as of 1.11.0)\nawait client.QueryAsync(\n\
\ collectionName: \"{collection_name}\",\n query: Sample.Random\n\
);\n"
language: csharp
- code-samples:
- code: "import static io.qdrant.client.QueryFactory.fusion;\nimport static\
Expand Down Expand Up @@ -1485,27 +1490,33 @@ paths:
\ {\n {0.1f, 0.2f},\n {0.2f,\
\ 0.1f},\n {0.8f, 0.9f}\n }))\n\
\ .setUsing(\"colbert\")\n .setLimit(10)\n \
\ .build())\n .get();"
\ .build())\n .get();\n\n// Random sampling (as of 1.11.0)\n\
client\n .queryAsync(\n QueryPoints.newBuilder()\n \
\ .setCollectionName(\"{collection_name}\")\n .setQuery(sample(Sample.Random))\n\
\ .build())\n .get();\n"
language: java
- code-samples:
- code: "import { QdrantClient } from \"@qdrant/js-client-rest\";\n\nconst\
\ client = new QdrantClient({ host: \"localhost\", port: 6333 });\n\n\
// Query nearest by ID\nclient.query(\"{collection_name\", {\n query:\
\ \"43cf51e2-8777-4f52-bc74-c2cbde0c8b04\"\n});\n\n// Recommend on the\
\ average of these vectors\nclient.query(\"{collection_name}\", {\n \
\ query: {\n recommend: {\n positive: [\"43cf51e2-8777-4f52-bc74-c2cbde0c8b04\"\
, [0.11, 0.35, 0.6]],\n negative: [0.01, 0.45, 0.67]\n \
\ }\n }\n});\n\n// Fusion query\nclient.query(\"{collection_name}\"\
// Query nearest by ID\nlet _nearest = client.query(\"{collection_name\"\
, {\n query: \"43cf51e2-8777-4f52-bc74-c2cbde0c8b04\"\n});\n\n// Recommend\
\ on the average of these vectors\nlet _recommendations = client.query(\"\
{collection_name}\", {\n query: {\n recommend: {\n \
\ positive: [\"43cf51e2-8777-4f52-bc74-c2cbde0c8b04\", [0.11, 0.35,\
\ 0.6]],\n negative: [0.01, 0.45, 0.67]\n }\n }\n\
});\n\n// Fusion query\nlet _hybrid = client.query(\"{collection_name}\"\
, {\n prefetch: [\n {\n query: {\n \
\ values: [0.22, 0.8],\n indices: [1, 42],\n \
\ },\n using: 'sparse',\n limit: 20,\n \
\ },\n {\n query: [0.01, 0.45, 0.67],\n using:\
\ 'dense',\n limit: 20,\n },\n ],\n query: {\n\
\ fusion: 'rrf',\n },\n});\n\n// 2-stage query\nclient.query(\"\
{collection_name}\", {\n prefetch: {\n query: [1, 23, 45, 67],\n\
\ limit: 100,\n },\n query: [\n [0.1, 0.2],\n \
\ [0.2, 0.1],\n [0.8, 0.9],\n ],\n using: 'colbert',\n\
\ limit: 10,\n});\n"
\ fusion: 'rrf',\n },\n});\n\n// 2-stage query\nlet _refined\
\ = client.query(\"{collection_name}\", {\n prefetch: {\n query:\
\ [1, 23, 45, 67],\n limit: 100,\n },\n query: [\n \
\ [0.1, 0.2],\n [0.2, 0.1],\n [0.8, 0.9],\n ],\n \
\ using: 'colbert',\n limit: 10,\n});\n\n// Random sampling (as of\
\ 1.11.0)\nlet _sampled = client.query(\"{collection_name}\", {\n query:\
\ { sample: \"random\" },\n});\n"
language: typescript
- code-samples:
- code: "from qdrant_client import QdrantClient, models\n\nclient = QdrantClient(url=\"\
Expand All @@ -1515,7 +1526,7 @@ paths:
\ collection_name=\"{collection_name}\",\n query=models.RecommendQuery(recommend=models.RecommendInput(\n\
\ positive=[\"43cf51e2-8777-4f52-bc74-c2cbde0c8b04\", [0.11, 0.35,\
\ 0.6, ...]],\n negative=[[0.01, 0.45, 0.67, ...]]\n ))\n)\n\
\n# Fusion query\nfusion = client.query_points(\n collection_name=\"\
\n# Fusion query\nhybrid = client.query_points(\n collection_name=\"\
{collection_name}\",\n prefetch=[\n models.Prefetch(\n \
\ query=models.SparseVector(indices=[1, 42], values=[0.22, 0.8]),\n\
\ using=\"sparse\",\n limit=20,\n ),\n \
Expand All @@ -1527,7 +1538,10 @@ paths:
\ 0.45, 0.67, ...], # <-- dense vector\n limit=100,\n ),\n\
\ query=[\n [0.1, 0.2, ...], # <\u2500\u2510\n [0.2,\
\ 0.1, ...], # < \u251C\u2500 multi-vector\n [0.8, 0.9, ...],\
\ # < \u2518\n ],\n using=\"colbert\",\n limit=10,\n)"
\ # < \u2518\n ],\n using=\"colbert\",\n limit=10,\n)\n\n# Random\
\ sampling (as of 1.11.0)\nsampled = client.query_points(\n collection_name=\"\
{collection_name}\",\n query=models.SampleQuery(sample=models.Sample.Random)\n\
)\n"
language: python
/collections/{collection_name}/points/query/batch:
post:
Expand Down
6 changes: 6 additions & 0 deletions snippets/csharp/query_points.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ await client.QueryAsync(
usingVector: "colbert",
limit: 10
);

// Random sampling (as of 1.11.0)
await client.QueryAsync(
collectionName: "{collection_name}",
query: Sample.Random
);
11 changes: 10 additions & 1 deletion snippets/java/query_points.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@
.setUsing("colbert")
.setLimit(10)
.build())
.get();
.get();

// Random sampling (as of 1.11.0)
client
.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("{collection_name}")
.setQuery(sample(Sample.Random))
.build())
.get();
10 changes: 8 additions & 2 deletions snippets/python/query_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)

# Fusion query
fusion = client.query_points(
hybrid = client.query_points(
collection_name="{collection_name}",
prefetch=[
models.Prefetch(
Expand Down Expand Up @@ -49,4 +49,10 @@
],
using="colbert",
limit=10,
)
)

# Random sampling (as of 1.11.0)
sampled = client.query_points(
collection_name="{collection_name}",
query=models.SampleQuery(sample=models.Sample.Random)
)
16 changes: 12 additions & 4 deletions snippets/rust/query_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use qdrant_client::qdrant::{Condition, Filter, PointId, PrefetchQueryBuilder, Qu
let client = Qdrant::from_url("http://localhost:6334").build()?;

// Query nearest by ID
client.query(
let _nearest = client.query(
QueryPointsBuilder::new("{collection_name}")
.query(Query::new_nearest(PointId::new("43cf51e2-8777-4f52-bc74-c2cbde0c8b04")))
).await?;

// Recommend on the average of these vectors
client.query(
let _recommendations = client.query(
QueryPointsBuilder::new("{collection_name}")
.query(Query::new_recommend(
RecommendInputBuilder::default()
Expand All @@ -20,7 +20,7 @@ client.query(
).await?;

// Fusion query
client.query(
let _hybrid = client.query(
QueryPointsBuilder::new("{collection_name}")
.add_prefetch(PrefetchQueryBuilder::default()
.query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))
Expand All @@ -36,7 +36,7 @@ client.query(
).await?;

// 2-stage query
client.query(
let _refined = client.query(
QueryPointsBuilder::new("{collection_name}")
.add_prefetch(PrefetchQueryBuilder::default()
.query(Query::new_nearest(vec![0.01, 0.45, 0.67]))
Expand All @@ -50,3 +50,11 @@ client.query(
.using("colbert")
.limit(10u64)
).await?;

// Random sampling (as of 1.11.0)
let _sampled = client
.query(
QueryPointsBuilder::new("{collection_name}")
.query(Query::new_sample(Sample::Random))
)
.await?;
13 changes: 9 additions & 4 deletions snippets/typescript/query_points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { QdrantClient } from "@qdrant/js-client-rest";
const client = new QdrantClient({ host: "localhost", port: 6333 });

// Query nearest by ID
client.query("{collection_name", {
let _nearest = client.query("{collection_name", {
query: "43cf51e2-8777-4f52-bc74-c2cbde0c8b04"
});

// Recommend on the average of these vectors
client.query("{collection_name}", {
let _recommendations = client.query("{collection_name}", {
query: {
recommend: {
positive: ["43cf51e2-8777-4f52-bc74-c2cbde0c8b04", [0.11, 0.35, 0.6]],
Expand All @@ -18,7 +18,7 @@ client.query("{collection_name}", {
});

// Fusion query
client.query("{collection_name}", {
let _hybrid = client.query("{collection_name}", {
prefetch: [
{
query: {
Expand All @@ -40,7 +40,7 @@ client.query("{collection_name}", {
});

// 2-stage query
client.query("{collection_name}", {
let _refined = client.query("{collection_name}", {
prefetch: {
query: [1, 23, 45, 67],
limit: 100,
Expand All @@ -53,3 +53,8 @@ client.query("{collection_name}", {
using: 'colbert',
limit: 10,
});

// Random sampling (as of 1.11.0)
let _sampled = client.query("{collection_name}", {
query: { sample: "random" },
});

0 comments on commit 8c19d94

Please sign in to comment.