Step 2: Connecting and Authenticating
In this step, we will connect to the database we created in Step 1 and authenticate using an API key.
Authentication
To authenticate with the database, you will need to generate an API key. To do this, navigate to the databases page and click the key symbol next to the database you want to access. Take note of the API key and the database ID.
Connecting
Once you've created a database and generated an API key, you can connect to the database using the client library.
Install the client library:
- JavaScript
- Python
npm install @svector/client
pip install svectordb
Next let's create the basic skeleton:
- JavaScript
- Python
const { DatabaseService } = require('@svector/client');
const region = 'us-east-2';
const apiKey = 'f4ead19a-bac7-4ff0-b379-d3f634ed180f'; // replace with your API key
const databaseId = 'f39434565486ee15'; // replace with your database ID
const client = new DatabaseService({
endpoint: `https://${region}.api.svectordb.com`,
apiKey: apiKey
});
(async () => {
// Code goes here
})()
import asyncio
import random
from svectordb.client import DatabaseService
from svectordb.config import Config
from svectordb.models import *
from smithy_core.retries import SimpleRetryStrategy
from smithy_http.aio.identity.apikey import ApiKeyIdentity, ApiKeyIdentityResolver
region = 'us-east-2'
apiKey = '2e607c5f-aaac-4d19-9824-4315b135484f' # replace with your API key
databaseId = 'e65c1cd5e2afbcec' # replace with your database ID
async def main() -> None:
client = DatabaseService(Config(
endpoint_uri=f"https://{region}.api.svectordb.com",
api_key_identity_resolver=ApiKeyIdentityResolver(api_key=ApiKeyIdentity(api_key=apiKey)),
retry_strategy=SimpleRetryStrategy(max_attempts=1)
))
# Code goes here
if __name__ == "__main__":
asyncio.run(main())