Skip to main content

BagelDB is a Python library for interacting with the BagelDB API.

Project description

Sure, here's a step-by-step guide on how to use the BagelDB Python client:

  1. Import the BagelDB client

    Start by importing the BagelDB client into your Python script.

    from BagelDB import BagelDB
    
  2. Initialize the BagelDB client

    Next, initialize a new instance of the BagelDB client. Make sure you have your OpenAI API key set in your environment variables as OPENAI_API_KEY.

    db = BagelDB()
    
  3. Ping the BagelDB server

    To check the connection to the BagelDB server, you can use the ping() method. This method will return a response from the BagelDB API in JSON format.

    response = db.ping()
    print(response)
    
  4. Get OpenAI embeddings

    Use the getOpenAIEmbedding(inputText, model='text-embedding-ada-002') method to get embeddings from OpenAI. The inputText is the text for which embeddings are required. model is optional and defaults to 'text-embedding-ada-002'.

    input_text = "Some text"
    embeddings = db.getOpenAIEmbedding(input_text)
    print(embeddings)
    
  5. Insert vectors into BagelDB

    To insert vectors into a given index in BagelDB, use the insert(index, vectors) method. index is the index in which vectors are to be inserted, and vectors is a list of vectors to be inserted.

    index = "myIndex"
    vectors = [{'id': 'vec1', 'values': [0.1, 0.2, 0.3], 'metadata': {'key': 'value'}}]
    insert_response = db.insert(index, vectors)
    print(insert_response)
    
  6. Search for a vector in BagelDB

    To search for a vector in a given index in BagelDB, use the search(index, vector) method. index is the index in which the search is to be performed, and vector is the vector for which the search is to be performed.

    index = "myIndex"
    vector = [0.1, 0.2, 0.3]
    search_response = db.search(index, vector)
    print(search_response)
    

Remember to handle exceptions in your application. The methods in the BagelDB client can raise exceptions if a network error occurs or if the response from the server indicates a failed HTTP status code.

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

betabageldb-0.1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

betabageldb-0.1.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

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