Skip to main content

Python client library for interacting with asimplevectors API.

Project description

asimplevectors Client Library

asimplevectors Client is a Python package providing an asynchronous API client to interact with the asimplevectors service, supporting vector management, search, space configuration, and RBAC-based security.

Features

  • Space Management: Create, update, delete, and list spaces with flexible configurations.
  • Versioning: Manage versions for spaces, including creating and retrieving specific versions.
  • Vector Operations: Upsert, retrieve, and search vectors with support for numpy arrays and lists.
  • RBAC Security: Manage tokens for role-based access control (RBAC) and apply them to secure API calls.
  • Snapshot Management: Create and manage snapshots of vector spaces.
  • Async Support: Fully asynchronous API for high-performance applications.

Installation

pip installation will be supported soon.

Requirements

Usage

Initialization

from asimplevectors.client import ASimpleVectorsClient

# Initialize the client
client = ASimpleVectorsClient(host="localhost", port=21001)

# Use async context manager to ensure session closure
async with client:
    ...

Example: Space Management

import asyncio

async def main():
    client = ASimpleVectorsClient(host="localhost")

    # Create a space
    create_space_data = {
        "name": "spacename",
        "dimension": 128,
        "metric": "L2"
    }
    await client.create_space(create_space_data)
    print("Space created successfully.")

    # List spaces
    spaces = await client.list_spaces()
    print("Available spaces:", spaces)

    await client.close()

asyncio.run(main())

Example: Vector Operations

import numpy as np
import asyncio

async def vector_operations():
    client = ASimpleVectorsClient(host="localhost")

    # Upsert vectors
    vector_data = {
        "vectors": [
            {"id": 1, "data": np.array([0.1, 0.2, 0.3, 0.4]), "metadata": {"label": "first"}}
        ]
    }
    await client.create_vector("spacename", vector_data)
    print("Vector upserted successfully.")

    # Retrieve vectors by version
    vectors = await client.get_vectors_by_version("spacename", version_id=0)
    print("Retrieved vectors:", vectors)

    await client.close()

asyncio.run(vector_operations())

Example: RBAC Token Management

async def manage_tokens():
    client = ASimpleVectorsClient(host="localhost")

    # Create an RBAC token
    token_data = {
        "user_id": 1,
        "space": 2,
        "vector": 2
    }
    await client.create_rbac_token(token_data)
    print("Token created successfully.")

    # List RBAC tokens
    tokens = await client.list_rbac_tokens()
    print("Available tokens:", tokens)

    await client.close()

asyncio.run(manage_tokens())

Development

Setting up the development environment

  1. Setup asimplevectors server from docker
docker pull billionvectors/asimplevectors:0.2.0
docker run -p 21001:21001 -p 21002:21002 asimplevectors:0.2.0
  1. Clone the repository:
git clone https://github.com/billionvectors/client_api.git
cd client_api
  1. Run test
cd python
./run_example.sh search

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asimplevectors-0.1.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

asimplevectors-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file asimplevectors-0.1.1.tar.gz.

File metadata

  • Download URL: asimplevectors-0.1.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for asimplevectors-0.1.1.tar.gz
Algorithm Hash digest
SHA256 860bb56577fb185cf0b64111992aa9211eb1a561b91a86f4dcb9ca616e7f7d10
MD5 358493a1d9dd00ef69c11516447e1327
BLAKE2b-256 edaac539c462a92ca9a4682d1506d2567894667b464703310daefb3c6c61a51b

See more details on using hashes here.

File details

Details for the file asimplevectors-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asimplevectors-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b360b3bf8a82b89ad608da06cf8994c753ff28223e0c53939db6a80b4fb40036
MD5 21fcc8a1c5171749a0b8491904000fcf
BLAKE2b-256 1975d3ed47c6010f62b273ea386e5a0110cf1d6d41e95a6445fe4fb097f250d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page