mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 21:08:31 +02:00
Fix type-checking errors in snippets (code only, no .md)
This commit both: - Fixes pre-existing mistakes in snippets, aka wrong code samples. - Adds hidden (`@hide`) statements that do not appear in the docs, but satisfy typecheckers.
This commit is contained in:
+4
-1
@@ -1,9 +1,12 @@
|
||||
|
||||
using Qdrant.Client; // @hide
|
||||
using Qdrant.Client.Grpc; // @hide
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334); // @hide
|
||||
|
||||
await client.CreateCollectionAsync(
|
||||
collectionName: "{collection_name}",
|
||||
vectorsConfig: new VectorParamsMap
|
||||
|
||||
+10
-1
@@ -1,8 +1,17 @@
|
||||
package snippet
|
||||
|
||||
|
||||
import "context" // @hide
|
||||
import "github.com/qdrant/go-client/qdrant" // @hide
|
||||
|
||||
func Main() {
|
||||
// @hide-start
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
if err != nil { panic(err) }
|
||||
// @hide-end
|
||||
|
||||
client.CreateCollection(context.Background(), &qdrant.CreateCollection{
|
||||
CollectionName: "{collection_name}",
|
||||
VectorsConfig: qdrant.NewVectorsConfigMap(
|
||||
|
||||
+14
-7
@@ -8,9 +8,15 @@ 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;
|
||||
import java.util.Map;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
// @hide-start
|
||||
io.qdrant.client.QdrantClient client =
|
||||
new io.qdrant.client.QdrantClient(io.qdrant.client.QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
// @hide-end
|
||||
|
||||
client
|
||||
.createCollectionAsync(
|
||||
CreateCollection.newBuilder()
|
||||
@@ -26,13 +32,14 @@ public class Snippet {
|
||||
.setSize(384)
|
||||
.setDistance(Distance.Cosine)
|
||||
.build())))
|
||||
.setSparseVectorsConfig(
|
||||
SparseVectorConfig.newBuilder()
|
||||
.putMap(
|
||||
"bm25_sparse_vector",
|
||||
SparseVectorParams.newBuilder()
|
||||
.setModifier(Modifier.Idf)
|
||||
.build())))
|
||||
.build())
|
||||
.setSparseVectorsConfig(
|
||||
SparseVectorConfig.newBuilder()
|
||||
.putMap(
|
||||
"bm25_sparse_vector",
|
||||
SparseVectorParams.newBuilder()
|
||||
.setModifier(Modifier.Idf)
|
||||
.build()))
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
|
||||
+2
@@ -4,6 +4,8 @@ use qdrant_client::qdrant::{
|
||||
};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = qdrant_client::Qdrant::from_url("http://localhost:6334").build()?; // @hide
|
||||
|
||||
let mut vector_config = VectorsConfigBuilder::default();
|
||||
vector_config.add_named_vector_params(
|
||||
"dense_vector",
|
||||
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var queryText = "What is relapsing polychondritis?"
|
||||
var queryText = "What is relapsing polychondritis?";
|
||||
_ = queryText; // @hide
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package snippet
|
||||
|
||||
|
||||
|
||||
func Main() {
|
||||
queryText := "What is relapsing polychondritis?"
|
||||
_ = queryText // @hide
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let query_text = "What is relapsing polychondritis?";
|
||||
|
||||
_ = query_text; // @hide
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,10 +1,6 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
import "github.com/qdrant/go-client/qdrant"
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
@@ -13,4 +9,7 @@ func Main() {
|
||||
APIKey: "<paste-your-api-key-here>",
|
||||
UseTLS: true,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) } // @hide
|
||||
_ = client // @hide
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
from qdrant_client import QdrantClient
|
||||
|
||||
qdrant_client = QdrantClient(
|
||||
client = QdrantClient(
|
||||
"xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||
api_key="<paste-your-api-key-here>",
|
||||
cloud_inference=True,
|
||||
timeout=30.0
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
+2
-2
@@ -1,6 +1,4 @@
|
||||
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")
|
||||
@@ -8,5 +6,7 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
_ = client; // @hide
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,9 +1,17 @@
|
||||
|
||||
using Qdrant.Client; // @hide
|
||||
using Qdrant.Client.Grpc; // @hide
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
// @hide-start
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
var queryText = "{query_text}";
|
||||
var denseModel = "{dense_model_name}";
|
||||
var bm25Model = "{bm25_model_name}";
|
||||
// @hide-end
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}", prefetch: new List <PrefetchQuery> {
|
||||
new() {
|
||||
|
||||
+14
-2
@@ -1,8 +1,20 @@
|
||||
package snippet
|
||||
|
||||
|
||||
import "context" // @hide
|
||||
import "github.com/qdrant/go-client/qdrant" // @hide
|
||||
|
||||
func Main() {
|
||||
// @hide-start
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
if err != nil { panic(err) }
|
||||
queryText := "{query_text}"
|
||||
denseModel := "{dense_model_name}"
|
||||
bm25Model := "{bm25_model_name}"
|
||||
// @hide-end
|
||||
|
||||
prefetch := []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Query: qdrant.NewQueryDocument(&qdrant.Document{
|
||||
@@ -20,7 +32,7 @@ func Main() {
|
||||
},
|
||||
}
|
||||
|
||||
client.Query(ctx, &qdrant.QueryPoints{
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Prefetch: prefetch,
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_RRF),
|
||||
|
||||
+8
@@ -10,6 +10,14 @@ import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
// @hide-start
|
||||
io.qdrant.client.QdrantClient client =
|
||||
new io.qdrant.client.QdrantClient(io.qdrant.client.QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
String queryText = "{query_text}";
|
||||
String denseModel = "{dense_model_name}";
|
||||
String bm25Model = "{bm25_model_name}";
|
||||
// @hide-end
|
||||
|
||||
PrefetchQuery densePrefetch =
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(
|
||||
|
||||
+9
-4
@@ -1,12 +1,17 @@
|
||||
from qdrant_client import QdrantClient, models # @hide
|
||||
# @hide-start
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333") # @hide
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
query_text = "{query_text}"
|
||||
dense_model = "{dense_model_name}"
|
||||
bm25_model = "{bm25_model_name}"
|
||||
# @hide-end
|
||||
|
||||
results = client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
prefetch=[
|
||||
models.Prefetch(
|
||||
query=Document(
|
||||
query=models.Document(
|
||||
text=query_text,
|
||||
model=dense_model
|
||||
),
|
||||
@@ -14,7 +19,7 @@ results = client.query_points(
|
||||
limit=5
|
||||
),
|
||||
models.Prefetch(
|
||||
query=Document(
|
||||
query=models.Document(
|
||||
text=query_text,
|
||||
model=bm25_model
|
||||
),
|
||||
|
||||
+10
-1
@@ -1,6 +1,13 @@
|
||||
use qdrant_client::qdrant::{Document, Fusion, PrefetchQueryBuilder, Query, QueryPointsBuilder};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
// @hide-start
|
||||
let client = qdrant_client::Qdrant::from_url("http://localhost:6334").build()?;
|
||||
let query_text = "{query_text}";
|
||||
let dense_model = "{dense_model_name}";
|
||||
let bm25_model = "{bm25_model_name}";
|
||||
// @hide-end
|
||||
|
||||
let dense_prefetch = PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(Document::new(query_text, dense_model)))
|
||||
.using("dense_vector")
|
||||
@@ -11,7 +18,7 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
.using("bm25_sparse_vector")
|
||||
.build();
|
||||
|
||||
let query_request = QueryPointsBuilder::new(collection_name)
|
||||
let query_request = QueryPointsBuilder::new("{collection_name}")
|
||||
.add_prefetch(dense_prefetch)
|
||||
.add_prefetch(bm25_prefetch)
|
||||
.query(Query::new_fusion(Fusion::Rrf))
|
||||
@@ -20,5 +27,7 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
|
||||
let results = client.query(query_request).await?;
|
||||
|
||||
_ = results; // @hide
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,8 +1,14 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
|
||||
// @hide-start
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
const results = await client.query(collectionName, {
|
||||
const queryText = "{query_text}";
|
||||
const denseModel = "{dense_model_name}";
|
||||
const bm25Model = "{bm25_model_name}";
|
||||
// @hide-end
|
||||
|
||||
const results = await client.query("{collection_name}", {
|
||||
prefetch: [
|
||||
{
|
||||
query: {
|
||||
|
||||
+10
-1
@@ -1,13 +1,22 @@
|
||||
|
||||
using Qdrant.Client; // @hide
|
||||
using Qdrant.Client.Grpc; // @hide
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334); // @hide
|
||||
|
||||
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.
|
||||
// @hide-start
|
||||
List<Dictionary<string, object>> LoadDataset(string path, string slice)
|
||||
{
|
||||
return new List<Dictionary<string, object>> {};
|
||||
}
|
||||
// @hide-end
|
||||
var dataset = LoadDataset("miriad/miriad-4.4M", "train[0:100]");
|
||||
var points = new List<PointStruct>();
|
||||
|
||||
|
||||
+21
-2
@@ -1,8 +1,27 @@
|
||||
package snippet
|
||||
|
||||
// @hide-start
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func loadDataset(name string, split string) []map[string]string {
|
||||
return []map[string]string{}
|
||||
}
|
||||
// @hide-end
|
||||
|
||||
func Main() {
|
||||
// @hide-start
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
if err != nil { panic(err) }
|
||||
// @hide-end
|
||||
|
||||
denseModel := "sentence-transformers/all-minilm-l6-v2"
|
||||
bm25Model := "qdrant/bm25"
|
||||
// NOTE: loadDataset is a user-defined function.
|
||||
@@ -27,8 +46,8 @@ func Main() {
|
||||
}
|
||||
points = append(points, point)
|
||||
}
|
||||
_, err = client.Upsert(ctx, &qdrant.UpsertPoints{
|
||||
CollectionName: "{collection_name},
|
||||
_, err = client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Points: points,
|
||||
})
|
||||
}
|
||||
|
||||
+14
-3
@@ -1,8 +1,8 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.VectorFactory.vector;
|
||||
import static io.qdrant.client.VectorsFactory.namedVectors;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.grpc.Points.Document;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
@@ -12,7 +12,18 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Snippet {
|
||||
// @hide-start
|
||||
private static List<Map<String, String>> loadDataset(String name, String split) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// @hide-end
|
||||
|
||||
public static void run() throws Exception {
|
||||
// @hide-start
|
||||
io.qdrant.client.QdrantClient client =
|
||||
new io.qdrant.client.QdrantClient(io.qdrant.client.QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
// @hide-end
|
||||
|
||||
String denseModel = "sentence-transformers/all-minilm-l6-v2";
|
||||
String bm25Model = "qdrant/bm25";
|
||||
// NOTE: loadDataset is a user-defined function.
|
||||
@@ -29,10 +40,10 @@ public class Snippet {
|
||||
namedVectors(
|
||||
Map.of(
|
||||
"dense_vector",
|
||||
vectors(
|
||||
vector(
|
||||
Document.newBuilder().setText(passage).setModel(denseModel).build()),
|
||||
"bm25_sparse_vector",
|
||||
vectors(
|
||||
vector(
|
||||
Document.newBuilder().setText(passage).setModel(bm25Model).build()))))
|
||||
.build();
|
||||
points.add(point);
|
||||
|
||||
+9
-1
@@ -2,12 +2,20 @@ use qdrant_client::qdrant::{
|
||||
Document, NamedVectors, PointStruct, UpsertPointsBuilder,
|
||||
};
|
||||
use qdrant_client::Payload;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = qdrant_client::Qdrant::from_url("http://localhost:6334").build()?; // @hide
|
||||
|
||||
let dense_model = "sentence-transformers/all-minilm-l6-v2";
|
||||
let bm25_model = "qdrant/bm25";
|
||||
// NOTE: load_dataset is a user-defined function.
|
||||
// Implement it to handle dataset loading as needed.
|
||||
// @hide-start
|
||||
fn load_dataset(_path: &str, _slice: &str) -> Vec<serde_json::Value> {
|
||||
vec![]
|
||||
}
|
||||
// @hide-end
|
||||
let dataset: Vec<_> = load_dataset("miriad/miriad-4.4M", "train[0:100]");
|
||||
|
||||
let points: Vec<PointStruct> = dataset
|
||||
@@ -29,7 +37,7 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
.collect();
|
||||
|
||||
client
|
||||
.upsert_points(UpsertPointsBuilder::new(collection_name, points))
|
||||
.upsert_points(UpsertPointsBuilder::new("{collection_name}", points))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
+5
@@ -8,6 +8,11 @@ const denseModel = "sentence-transformers/all-minilm-l6-v2";
|
||||
const bm25Model = "qdrant/bm25";
|
||||
// NOTE: loadDataset is a user-defined function.
|
||||
// Implement it to handle dataset loading as needed.
|
||||
// @hide-start
|
||||
function loadDataset(name: string, slice: string): Array<{ passage_text: string }> {
|
||||
return [];
|
||||
}
|
||||
// @hide-end
|
||||
const dataset = loadDataset("miriad/miriad-4.4M", "train[0:100]");
|
||||
|
||||
const points = dataset.map((item) => {
|
||||
|
||||
Reference in New Issue
Block a user