REST API

How to Use the Deep Lake REST API

Overview of the Managed Database REST API

The Deep Lake Tensor Database can be accessed via REST API. The datasets must be stored in the Tensor Database by specifying the deeplake_path = hub://org_id/dataset_name and runtime = {"tensor_db": True}. Full details on path and storage management are available here.

Querying via the REST API

The primary input to the query API is a query string that contains all the necessary information for executing the query, including the path to the Deep Lake data. Full details on the query syntax are available here.

Input

url = "https://app.activeloop.ai/api/query/v1"

headers = {
    "Authorization": f"Bearer {user_token}"
    }

# Format the embedding array or list as a string, so it can be passed in the REST API request.
embedding_string = ",".join([str(item) for item in embedding])

request = {
    "query": f"select * from (select text, cosine_similarity(embedding, ARRAY[{embedding_string}]) as score from \"{dataset_path}\") order by score desc limit 5",
    "as_list": True/False # Defaults to True.
    }

Response

If as_list = True (default). Returns a list of jsons, one per row.

If as_list = False. Returns a list of values per tensor.

Was this helpful?