mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-11 05:48:31 +02:00
docs: Added more snippets to the hybrid search with cloud inference tutorial (#1953)
* docs: More snippets Signed-off-by: Anush008 <anushshetty90@gmail.com> * docs: Review update Signed-off-by: Anush008 <anushshetty90@gmail.com> --------- Signed-off-by: Anush008 <anushshetty90@gmail.com>
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
|||||||
|
```csharp
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
```go
|
||||||
|
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(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
})
|
||||||
|
```
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
```java
|
||||||
|
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;
|
||||||
|
|
||||||
|
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();
|
||||||
|
```
|
||||||
+3
-6
@@ -1,11 +1,8 @@
|
|||||||
```python
|
```python
|
||||||
from qdrant_client import models
|
from qdrant_client import models
|
||||||
|
|
||||||
collection_name = "my_collection_name"
|
client.create_collection(
|
||||||
|
collection_name="{collection_name}",
|
||||||
if not client.collection_exists(collection_name=collection_name):
|
|
||||||
client.create_collection(
|
|
||||||
collection_name=collection_name,
|
|
||||||
vectors_config={
|
vectors_config={
|
||||||
"dense_vector": models.VectorParams(
|
"dense_vector": models.VectorParams(
|
||||||
size=384,
|
size=384,
|
||||||
@@ -17,5 +14,5 @@ if not client.collection_exists(collection_name=collection_name):
|
|||||||
modifier=models.Modifier.IDF # Enable Inverse Document Frequency
|
modifier=models.Modifier.IDF # Enable Inverse Document Frequency
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
```rust
|
||||||
|
use qdrant_client::qdrant::{
|
||||||
|
CreateCollectionBuilder, Distance, Modifier, SparseVectorParamsBuilder,
|
||||||
|
SparseVectorsConfigBuilder, VectorParamsBuilder, VectorsConfigBuilder,
|
||||||
|
};
|
||||||
|
|
||||||
|
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?;
|
||||||
|
```
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
```typescript
|
||||||
|
client.createCollection("{collection_name}", {
|
||||||
|
vectors: {
|
||||||
|
dense_vector: { size: 384, distance: "Cosine" },
|
||||||
|
},
|
||||||
|
sparse_vectors: {
|
||||||
|
bm25_sparse_vector: {
|
||||||
|
modifier: "idf" // Enable Inverse Document Frequency
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
```csharp
|
||||||
|
var queryText = "What is relapsing polychondritis?"
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
```go
|
||||||
|
queryText := "What is relapsing polychondritis?"
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
```java
|
||||||
|
String queryText = "What is relapsing polychondritis?";
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
```rust
|
||||||
|
let query_text = "What is relapsing polychondritis?";
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
```typescript
|
||||||
|
let query_text = "What is relapsing polychondritis?";
|
||||||
|
```
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
```csharp
|
||||||
|
using Qdrant.Client;
|
||||||
|
|
||||||
|
var client = new QdrantClient(
|
||||||
|
host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||||
|
https: true,
|
||||||
|
apiKey: "<paste-your-api-key-here>"
|
||||||
|
);
|
||||||
|
```
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
```go
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/qdrant/go-client/qdrant"
|
||||||
|
)
|
||||||
|
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
```
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
```java
|
||||||
|
import io.qdrant.client.QdrantClient;
|
||||||
|
import io.qdrant.client.QdrantGrpcClient;
|
||||||
|
|
||||||
|
QdrantClient client =
|
||||||
|
new QdrantClient(
|
||||||
|
QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
|
||||||
|
.withApiKey("<paste-your-api-key-here>")
|
||||||
|
.build());
|
||||||
|
```
|
||||||
+5
-3
@@ -1,7 +1,9 @@
|
|||||||
```python
|
```python
|
||||||
client = QdrantClient(
|
from qdrant_client import QdrantClient
|
||||||
url="https://YOUR_URL.eastus-0.azure.cloud.qdrant.io:6333/",
|
|
||||||
api_key="YOUR_API_KEY",
|
qdrant_client = QdrantClient(
|
||||||
|
"xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||||
|
api_key="<paste-your-api-key-here>",
|
||||||
cloud_inference=True,
|
cloud_inference=True,
|
||||||
timeout=30.0
|
timeout=30.0
|
||||||
)
|
)
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
```rust
|
||||||
|
use qdrant_client::Qdrant;
|
||||||
|
use qdrant_client::qdrant::{Document};
|
||||||
|
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
|
||||||
|
|
||||||
|
let client = Qdrant::from_url("https://xyz-example.qdrant.io:6334")
|
||||||
|
.api_key("<paste-your-api-key-here>")
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
```
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
```typescript
|
||||||
|
import {QdrantClient} from "@qdrant/js-client-rest";
|
||||||
|
|
||||||
|
const client = new QdrantClient({
|
||||||
|
url: 'https://xyz-example.qdrant.io:6333',
|
||||||
|
apiKey: '<paste-your-api-key-here>',
|
||||||
|
});
|
||||||
|
```
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
```csharp
|
||||||
|
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
|
||||||
|
);
|
||||||
|
```
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
```go
|
||||||
|
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),
|
||||||
|
})
|
||||||
|
```
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
```java
|
||||||
|
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;
|
||||||
|
|
||||||
|
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();
|
||||||
|
```
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
```python
|
```python
|
||||||
results = client.query_points(
|
results = client.query_points(
|
||||||
collection_name=collection_name,
|
collection_name="{collection_name}",
|
||||||
prefetch=[
|
prefetch=[
|
||||||
models.Prefetch(
|
models.Prefetch(
|
||||||
query=Document(
|
query=Document(
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
```rust
|
||||||
|
use qdrant_client::qdrant::{Document, Fusion, PrefetchQueryBuilder, Query, QueryPointsBuilder};
|
||||||
|
|
||||||
|
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?;
|
||||||
|
```
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
```typescript
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
```csharp
|
||||||
|
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
|
||||||
|
);
|
||||||
|
```
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
```go
|
||||||
|
denseModel := "sentence-transformers/all-minilm-l6-v2"
|
||||||
|
bm25Model := "qdrant/bm25"
|
||||||
|
// NOTE: loadDataset is a user-defined function.
|
||||||
|
// Implement it to handle dataset loading as needed.
|
||||||
|
dataset := loadDataset("miriad/miriad-4.4M", "train[0:100]")
|
||||||
|
points := make([]*qdrant.PointStruct, 0, 100)
|
||||||
|
|
||||||
|
for _, item := range dataset {
|
||||||
|
passage := item["passage_text"]
|
||||||
|
point := &qdrant.PointStruct{
|
||||||
|
Id: qdrant.NewID(uuid.New().String()),
|
||||||
|
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{
|
||||||
|
"dense_vector": qdrant.NewVectorDocument(&qdrant.Document{
|
||||||
|
Text: passage,
|
||||||
|
Model: denseModel,
|
||||||
|
}),
|
||||||
|
"bm25_sparse_vector": qdrant.NewVectorDocument(&qdrant.Document{
|
||||||
|
Text: passage,
|
||||||
|
Model: bm25Model,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
points = append(points, point)
|
||||||
|
}
|
||||||
|
_, err = client.Upsert(ctx, &qdrant.UpsertPoints{
|
||||||
|
CollectionName: "{collection_name},
|
||||||
|
Points: points,
|
||||||
|
})
|
||||||
|
```
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
```java
|
||||||
|
import static io.qdrant.client.PointIdFactory.id;
|
||||||
|
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;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
String denseModel = "sentence-transformers/all-minilm-l6-v2";
|
||||||
|
String bm25Model = "qdrant/bm25";
|
||||||
|
// NOTE: loadDataset is a user-defined function.
|
||||||
|
// Implement it to handle dataset loading as needed.
|
||||||
|
List<Map<String, String>> dataset = loadDataset("miriad/miriad-4.4M", "train[0:100]");
|
||||||
|
List<PointStruct> points = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map<String, String> item : dataset) {
|
||||||
|
String passage = item.get("passage_text");
|
||||||
|
PointStruct point =
|
||||||
|
PointStruct.newBuilder()
|
||||||
|
.setId(id(UUID.randomUUID()))
|
||||||
|
.setVectors(
|
||||||
|
namedVectors(
|
||||||
|
Map.of(
|
||||||
|
"dense_vector",
|
||||||
|
vectors(
|
||||||
|
Document.newBuilder().setText(passage).setModel(denseModel).build()),
|
||||||
|
"bm25_sparse_vector",
|
||||||
|
vectors(
|
||||||
|
Document.newBuilder().setText(passage).setModel(bm25Model).build()))))
|
||||||
|
.build();
|
||||||
|
points.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.upsertAsync("{collection_name}", points).get();
|
||||||
|
```
|
||||||
+1
-1
@@ -31,7 +31,7 @@ for idx, item in enumerate(ds):
|
|||||||
points.append(point)
|
points.append(point)
|
||||||
|
|
||||||
client.upload_points(
|
client.upload_points(
|
||||||
collection_name=collection_name,
|
collection_name="{collection_name}",
|
||||||
points=points,
|
points=points,
|
||||||
batch_size=8
|
batch_size=8
|
||||||
)
|
)
|
||||||
|
|||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
```rust
|
||||||
|
use qdrant_client::qdrant::{
|
||||||
|
Document, NamedVectors, PointStruct, UpsertPointsBuilder,
|
||||||
|
};
|
||||||
|
use qdrant_client::Payload;
|
||||||
|
|
||||||
|
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.
|
||||||
|
let dataset: Vec<_> = load_dataset("miriad/miriad-4.4M", "train[0:100]");
|
||||||
|
|
||||||
|
let points: Vec<PointStruct> = dataset
|
||||||
|
.iter()
|
||||||
|
.map(|item| {
|
||||||
|
let passage = item["passage_text"].as_str().unwrap();
|
||||||
|
let vectors = NamedVectors::default()
|
||||||
|
.add_vector(
|
||||||
|
"dense_vector",
|
||||||
|
Document::new(passage, dense_model),
|
||||||
|
)
|
||||||
|
.add_vector(
|
||||||
|
"bm25_sparse_vector",
|
||||||
|
Document::new(passage, bm25_model),
|
||||||
|
);
|
||||||
|
let payload = Payload::try_from(item.clone()).unwrap();
|
||||||
|
PointStruct::new(Uuid::new_v4().to_string(), vectors, payload)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
client
|
||||||
|
.upsert_points(UpsertPointsBuilder::new(collection_name, points))
|
||||||
|
.await?;
|
||||||
|
```
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
```typescript
|
||||||
|
import { randomUUID } from "crypto";
|
||||||
|
|
||||||
|
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.
|
||||||
|
const dataset = loadDataset("miriad/miriad-4.4M", "train[0:100]");
|
||||||
|
|
||||||
|
const points = dataset.map((item) => {
|
||||||
|
const passage = item.passage_text;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: randomUUID().toString(),
|
||||||
|
vector: {
|
||||||
|
dense_vector: {
|
||||||
|
text: passage,
|
||||||
|
model: denseModel,
|
||||||
|
},
|
||||||
|
bm25_sparse_vector: {
|
||||||
|
text: passage,
|
||||||
|
model: bm25Model,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.upsert("{collection_name}", { points });
|
||||||
|
```
|
||||||
+1
-4
@@ -7,10 +7,7 @@ In this tutorial, we'll walkthrough building a **hybrid semantic search engine**
|
|||||||
- Automatically embed your data using [cloud Inference](/documentation/cloud/inference/) without needing to run local models,
|
- Automatically embed your data using [cloud Inference](/documentation/cloud/inference/) without needing to run local models,
|
||||||
- Combine dense semantic embeddings with [sparse BM25 keywords](https://qdrant.tech/documentation/advanced-tutorials/reranking-hybrid-search/), and
|
- Combine dense semantic embeddings with [sparse BM25 keywords](https://qdrant.tech/documentation/advanced-tutorials/reranking-hybrid-search/), and
|
||||||
- Perform hybrid search using [Reciprocal Rank Fusion (RRF)](https://qdrant.tech/documentation/concepts/hybrid-queries/) to retrieve the most relevant results.
|
- Perform hybrid search using [Reciprocal Rank Fusion (RRF)](https://qdrant.tech/documentation/concepts/hybrid-queries/) to retrieve the most relevant results.
|
||||||
## Install Qdrant Client
|
|
||||||
```bash
|
|
||||||
pip install qdrant-client datasets
|
|
||||||
```
|
|
||||||
## Initialize the Client
|
## Initialize the Client
|
||||||
Initialize the Qdrant client after creating a [Qdrant Cloud account](/documentation/cloud/) and a [dedicated paid cluster](/documentation/cloud/create-cluster/). Set `cloud_inference` to `True` to enable [cloud inference](/documentation/cloud/inference/).
|
Initialize the Qdrant client after creating a [Qdrant Cloud account](/documentation/cloud/) and a [dedicated paid cluster](/documentation/cloud/create-cluster/). Set `cloud_inference` to `True` to enable [cloud inference](/documentation/cloud/inference/).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user