mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-27 15:08:30 +02:00
Update neural search tutorial to use 0.8.4 API (#66)
* Update neural search tutorial to use 0.8.4 API * Update neural-search-tutorial.md Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com>
This commit is contained in:
co-authored by
Andrey Vasnetsov
parent
d1987818da
commit
ed2b006ea1
@@ -171,7 +171,11 @@ Many independent vector collections can exist on one service at the same time.
|
|||||||
Let's create a new collection for our startup vectors.
|
Let's create a new collection for our startup vectors.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
qdrant_client.recreate_collection(collection_name='startups', vector_size=768)
|
qdrant_client.recreate_collection(
|
||||||
|
collection_name='startups',
|
||||||
|
vector_size=768,
|
||||||
|
distance="Cosine"
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
The `recreate_collection` function first tries to remove an existing collection with the same name.
|
The `recreate_collection` function first tries to remove an existing collection with the same name.
|
||||||
@@ -182,6 +186,8 @@ It tells the service the size of the vectors in that collection.
|
|||||||
All vectors in a collection must have the same size, otherwise, it is impossible to calculate the distance between them.
|
All vectors in a collection must have the same size, otherwise, it is impossible to calculate the distance between them.
|
||||||
`768` is the output dimensionality of the encoder we are using.
|
`768` is the output dimensionality of the encoder we are using.
|
||||||
|
|
||||||
|
The `distance` parameter allows specifying the function used to measure the distance between two points.
|
||||||
|
|
||||||
The Qdrant client library defines a special function that allows you to load datasets into the service.
|
The Qdrant client library defines a special function that allows you to load datasets into the service.
|
||||||
However, since there may be too much data to fit a single computer memory, the function takes an iterator over the data as input.
|
However, since there may be too much data to fit a single computer memory, the function takes an iterator over the data as input.
|
||||||
|
|
||||||
@@ -252,7 +258,7 @@ The search function looks as simple as possible:
|
|||||||
```python
|
```python
|
||||||
def search(self, text: str):
|
def search(self, text: str):
|
||||||
# Convert text query into vector
|
# Convert text query into vector
|
||||||
vector = self.model.encode(text)
|
vector = self.model.encode(text).tolist()
|
||||||
|
|
||||||
# Use `vector` for search for closest vectors in the collection
|
# Use `vector` for search for closest vectors in the collection
|
||||||
search_result = self.qdrant_client.search(
|
search_result = self.qdrant_client.search(
|
||||||
@@ -261,10 +267,9 @@ The search function looks as simple as possible:
|
|||||||
query_filter=None, # We don't want any filters for now
|
query_filter=None, # We don't want any filters for now
|
||||||
top=5 # 5 the most closest results is enough
|
top=5 # 5 the most closest results is enough
|
||||||
)
|
)
|
||||||
|
|
||||||
# `search_result` contains found vector ids with similarity scores along with the stored payload
|
# `search_result` contains found vector ids with similarity scores along with the stored payload
|
||||||
# In this function we are interested in payload only
|
# In this function we are interested in payload only
|
||||||
payloads = [payload for point, payload in search_result]
|
payloads = [hit.payload for hit in search_result]
|
||||||
return payloads
|
return payloads
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -272,7 +277,7 @@ With Qdrant it is also feasible to add some conditions to the search.
|
|||||||
For example, if we wanted to search for startups in a certain city, the search query could look like this:
|
For example, if we wanted to search for startups in a certain city, the search query could look like this:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from qdrant_openapi_client.models.models import Filter
|
from qdrant_client.http.models.models import Filter
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user