Quickstart
Welcome to the Quickstart Guide for KDB.AI; a vector database that empowers you to leverage your embeddings for building advanced AI applications. This guide outlines the essential steps to kickstart your journey.
- Sign-up for KDB.AI here
- Generate your API key(s)
- Install KDBAI client
- Connect to the KDB.AI database
- Create your first index
Install KDB.AI client
Installing the latest version of KDB.AI via pip from PyPI with the following command:
pip install kdbai-client
KDB.AI only supports Python versions >= 3.8
Set up the your KDB.AI API key
To use KDB.AI you need two session details: a hostname and an API key.
Cloud: Visit the console to generate your API Key. (link to the cloud section)
Initiate the KDB.AI client
To access KDB.AI and it's functionality, import it within your Python code using the following syntax:
import kdbai_client as kdbai
Connect with the KDB.AI server
Establish and verify the connection with the KDB.AI server:
session = kdbai.Session(host='XXXX.kdb.ai', api_key='YOUR_KDBAI_API_KEY')
Create a new table
To create a new table you must first set the schema. This is defined as a python dictionary that contains a list of columns. For each column you need to define the name and either a pytype
or a qtype
. The vector embeddings column should contain a vectorIndex
attribute with the configuration of the index for similarity search. Full schema definition specifications are available in the manage tables section.
schema = {'columns': [{'name': 'id', 'pytype': 'str'},
{'name': 'vectors',
'vectorIndex': {'dims': 8, 'metric': 'L2', 'type': 'flat'}}]}
table = session.create_table('quickstartkdbai',schema)
Retrieve a list of tables
Upon successful execution of the aforementioned steps, the recently created table is listed among the available tables of the current session.
session.list()
['quickstartkdbai']
Insert vector data
First, generate a vector of 5 8-dimensional vectors that will be the vector embeddings in this example. You can then add these to pandas dataframe with column names/types matching the table schema.
ids = ['h', 'e', 'l', 'l', 'o'] # Example ID values
vectors = np.random.rand(40).astype(np.float32).reshape(5,8)
df = pd.DataFrame({"id": ids, "vectors": list(vectors)})
table.insert(df)
Run similarity search
The dimension of input query vectors must match the vector embedding dimensions in the table, defined in schema above.
table.search(vectors=[[0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]], n=3)
The closest matching neighbor for the query vector passed through is returned along with the calculation of L2 (Euclidean Distance) similarity.
The search API supports batch querying and filtered search.
Delete the table and associated index
Use table.drop() to delete a table.
table.drop()
True
Next steps
- Learn the basic operations.
- Explore the available indexes.
Samples
Explore our samples on our Learning Hub.