Skip to main content
Version: 0.6.0

Vector Store

Seaplane comes with a built-in vector store to build powerful data science and machine learning applications. The Seaplane SDK hides all the complexity of setting up and connecting to the vector store and hands you a single object to interact with. Authentication is handled automatically by your API key. You can read more about authentication here.

You can add the vector store to any task by importing it from the main Seaplane package from seaplane.vector import vector_store.

from seaplane.vector import vector_store

def my_vector_store_task(msg):
# do something with your vector_store
vector_store.create_index('my-index', 768)

Index Operations​

Creating An Index​

In vector stores, a database is known as an index sometimes referred to as a collection. You can create new indexes by calling create_index() and passing two arguments. All vectors inside a single index need to have the same dimension.

Input variables:

  • The preferred index name - type:string
  • The index dimension - type:int
from seaplane.vector import vector_store

def my_vector_store_task(msg):
dimension = 3
vector_store.create_index("my-index", dimension)

Keep in mind that calling create_index inside a task executes it every time the task is called. This can cause the following error.

b'{"status":{"error":"Wrong input: Collection `<index-name>` already exists!"},"time":0.012740604}'

Resolve this by checking if the index exists before creating it.

from seaplane.vector import vector_store

def my_vector_store_task(msg):
dimension = 3
index_name = "my_index"

# create index if it does not exist
if index_name not in vector_store.list_indexes():
vector_store.create_index(index_name, dimension)

Alternatively, you can use the recreate_index method. Keep in mind that recreating an index deletes all data in any existing index with the same name.

Deleting An Index​

To delete an index call delete_index() and pass the following arguments.

Input Variable:

  • The index name - type:string
from seaplane.vector import vector_store

def my_vector_store_task(msg):
vector_store.delete_index("my-index")

Vector Operations​

Creating a new Vector​

Most vector operations require the use of the Vector types.

Input Variables

  • A vector (required) - type:list
  • Metadata (optional) - type:dict
  • ID (optional), if no ID is assigned the SDK generates one for you based on uuid4 - type:string.

You can construct a new Vector as follows.

from seaplane.vector import Vector

vector = Vector(vector=[1,2,3], metadata={"foo" : "bar"})

Inserting A Vector​

To insert a vector call the insert() method on the vector_store object. You can only insert vectors with the same dimension as the index.

Input Variables:

  • The index name where to insert the vector - type:string
  • A list of vectors - type:list with elements of type:Vector containing:
    • vector (required) - type:list
    • id (optional) - type:string
    • metadata (optional) - type:dict
from seaplane.vector import vector_store, Vector
import uuid

def my_vector_store_task(msg):
vector = Vector(vector=[1,2,3], metadata={"foo" : "bar"}, id=str(uuid.uuid4()))
vector_store.insert('my_index_name', [vector])

Deleting A Vector​

To delete a vector call the delete_vectors() method on the vector_store object.

Input Variables

  • The index name - type:string
  • The vector IDs - type:list with elements of type:string
from seaplane.vector import vector_store

def my_vector_store_task(msg):
vector_store.delete_vectors('my-index', ['my-vector-id'])

Updating A Vector​

To update a vector call the update() method on the vector_store object. You can only update vectors with the same dimensions as the underlying index. Seaplane finds the vectors to update based on the id as provided in the Vector

Input Variables:

  • The index name - type:string
  • A list of vectors to update - type:list with elements of type:Vector containing:
    • vector (required) - type:list
    • id (required) - type:string
    • metadata (optional) - type:dict
from seaplane.vector import vector_store, Vector

def my_vector_store_task(msg):
vector = Vector(vector=[1,2,3], metadata={"foo" : "bar"}, id='my-vector-id')
vector_store.update('my-index', [vector])

Search Methods​

K Nearest Neighbor Search (KNN)​

KNN search is a popular search algorithm used for similarity search tasks where the goal is to find the K nearest neighbors to a given query vector (where K∈ZK \in \Z). It is commonly used in various domains such as recommendation systems, image recognition, natural language processing, and much more.

Input Variables:

  • Index name type:string
  • Query vector type:Vector
  • K, the number of neighbors to return type:int
from seaplane.vector import vector_store, Vector

def my_vector_store_task(msg):
vector = Vector(vector=[1,2,3])
vector_store.knn_search('my_index_name', vector, 3)