Skip to content

Quick Start

Run Vektonn

In order to run Vektonn locally you will need to install Docker.

Run Vektonn configured for QuickStart examples:

1
2
3
git clone https://github.com/vektonn/vektonn-examples.git /path/to/vektonn-examples

/path/to/vektonn-examples/docker/run-vektonn.sh QuickStart.Index

Look at docker-compose.yaml to understand how to setup local Vektonn with single Index shard. Docker images for Vektonn are published on Docker Hub.

Use Vektonn API with a Python client

You will need Python >= 3.7 to run this sample.

  1. Install Vektonn SDK for Python:
1
pip install vektonn
  1. Initialize Vektonn client:
1
2
3
from vektonn import Vektonn

vektonn_client = Vektonn('http://localhost:8081')
  1. Upload data to Vektonn:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from vektonn.dtos import Attribute, AttributeValue, InputDataPoint, Vector

vektonn_client.upload(
    data_source_name='QuickStart.Source',
    data_source_version='1.0',
    input_data_points=[
        InputDataPoint(
            attributes=[
                Attribute(key='id', value=AttributeValue(int64=1)),
                Attribute(key='payload', value=AttributeValue(string='sample data point')),
            ],
            vector=Vector(is_sparse=False, coordinates=[3.14, 2.71]))
    ])
  1. Search for k nearest data points to the given query_vector:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from vektonn.dtos import Vector, SearchQuery

k = 10
query_vector = Vector(is_sparse=False, coordinates=[1.2, 3.4])

search_results = vektonn_client.search(
    index_name='QuickStart.Index',
    index_version='1.0',
    search_query=SearchQuery(k=k, query_vectors=[query_vector]))

print(f'For query vector {query_vector.coordinates} {k} nearest data points are:')
for fdp in search_results[0].nearest_data_points:
    attrs = {x.key : x.value for x in fdp.attributes}
    distance, vector, dp_id, payload = fdp.distance, fdp.vector, attrs['id'].int64, attrs['payload'].string
    print(f' - "{payload}" with id = {dp_id}, vector = {vector.coordinates}, distance = {distance}')

What's next

Take a look at Jupyter notebooks with several examples of solving problems similar to real ones using vector spaces and Vektonn:

  1. Hotels. Task: save the user's time while searching for hotels. This example uses vectorized user reviews to find hotels.

  2. Price Match Guarantee. Task: help the seller establish a competitive price for their product on the marketplace.

  3. Books. Task: find similar books by user reviews. This example demonstrates usage of sparse vectors.