Database

Create, Delete, List, and Query from a Database

Introduction

A database is a ClearAI term used to describe the location content and its embeddings are stored. These docs are meant to help a user create a database, list available databases, delete a database, and query a database.

Endpoint Details

To accomplish any of these actions on a database, the user can make use of the following endpoints. All endpoints are hosted by https://www.clearai.net. While each endpoint has unique input parameters, every API request need have an authorization header with a user's global API key. A user can access this key on the profile page.

Authorization Header (string, required): An HTTP header containing an authorization token in the format "Bearer YOUR_API_KEY". Replace YOUR_API_KEY with your valid API key. See the example below for how to implement this in the command line.

/api/database/create/v1

Parameters:

name (string, required): The name you wish to give the database.

Example:

curl -X POST \                                                                                
  -H "Content-Type: application/json" \   
  -H "Authorization: Bearer GLOBAL_KEY" \
  -d '{                                                            
    "name": "Whales"  }'                                             
  http://localhost:8000/api/database/create/v

Response:

{
    "database": {
        "key": "jBd18j6wW8c1",
        "name": "Whales"
    },
    "msg": "Folder created."
}

Delete

This API is currently in progress. Please use the console to delete Databases.

List

/api/database/list/v1

Parameters:

NONE

Example:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 11lNNAp9W7y5" \
  -d "" \
  http://localhost:8000/api/database/list/v1

Response:

{
    "Databases": [
        {
            "1": [
                {
                    "name": "Vacuum 9xD"
                },
                {
                    "key": "key_value"
                }
            ]
        },
        {
            "2": [
                {
                    "name": "Veggie Slicer"
                },
                {
                    "key": "key_value"
                }
            ]
        }
    ]
}

Query

/api/database/query/v1

Parameters:

This endpoint expects a JSON request with the following fields:

  • msg (string, required): The input message or text prompt that you want the AI model to generate a response for.

  • metadata (string, optional): Additional metadata information in JSON format. This field is optional but can be useful for context or tracking purposes.

  • minLength (integer, optional): The minimum desired number of sentences of the generated response. If not provided, a default of 1 sentence is assumed.

  • maxLength (integer, optional): The maximum desired number of sentences of the generated response. If not provided, a default of 20 sentences is assumed.

  • prompt (string, optional): The intended persona the model undertakes. The default is "assistant."

  • model (string): The generative artificial intelligence model selected to response to the inquiry. The current model options are gpt-4, gpt-3.5-turbo, gpt-3.5, claude-v2, and claude-instant-v1.

  • stream(boolean, optional): True or False

Example Request:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer GLOBAL_KEY" \
  -d '{
    "msg": "What are some additional resources I can use to study Whales? Please provide links if relevant.",
    "minLength": 3,
    "maxLength": 6,
    "stream":true,
    "model":"claude-instant-v1",
    "dbKey":"DB_KEY"
      }' https://clearai.net/api/database/query/v1 -N

Response (No Stream):

The endpoint will respond with a JSON object containing the generated reply and other relevant information:

  • msg (string): The original input message.

  • reply (string): The generated response from the AI model.

Response (Streaming):

The response will send the reply as text as the model produces it.

  • @@@END@@@ signifies that the output has ended.

Successful Response (HTTP Status Code: 200)

{
  "msg": "Generate a creative story about space exploration.",
  "reply": "Once upon a time, in the vast expanse of space..."
}

Error Response (HTTP Status Code: 400)

In case of errors, you will receive an error message in the response:

{
  "msg": "Generate a creative story about space exploration.",
  "reply": "Please provide a valid key."
}

Error Handling

  • If the Authorization header is missing or incorrect, you will receive a 400 status code with an error message.

  • If the metadata field is not a valid JSON string, you will receive a 400 status code with an error message.

  • If there is any issue with the AI model or server, you will receive a 500 status code with a generic error message.

Usage Guidelines

  • Ensure that you have a valid API key and include it in the Authorization header for authentication.

  • Keep the input message (msg) concise and relevant to get the best results from the AI model.

  • You can adjust the response length by specifying the length parameter in the request.

  • Use the metadata field to provide context or additional information to improve response quality.

Conclusion

You now have the essential information to start using the database endpoints to harness the power of the GPT-4 AI model for generating text-based responses. Feel free to integrate this API into your applications and services for a wide range of natural language processing tasks.

Last updated