Skip to main content

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

Project description

Here's a step by step guide on how to use BagelDB python client.

  1. Import the BagelDB client

    Start by importing the BagelDB client into your Python script.

    from betabageldb import BagelDB
    
  2. Initialize the BagelDB client

    Initialize a new instance of the BagelDB client. You need to specify the index you want to work with at this stage. This index will be used for all subsequent insertions and searches. Make sure you have your OpenAI API key set in your environment variables as OPENAI_API_KEY.

    index = "myIndex"
    db = BagelDB(index)
    
  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 BagelDB, use the insert(vectors) method. vectors is a list of vectors to be inserted. The index is already set during the initialization of the BagelDB client and is not required here.

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

    To search for a vector in BagelDB, use the search(vector) method. vector is the vector for which the search is to be performed. The index is already set during the initialization of the BagelDB client and is not required here.

    vector = [0.1, 0.2, 0.3]
    search_response = db.search(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.

  1. Insert vectors from texts

    The insertFromTexts(texts, model='text-embedding-ada-002') method can be used to convert a list of texts to their respective embeddings and insert these as vectors into BagelDB. The texts parameter is a list of strings for which embeddings are required, and model is optional and defaults to 'text-embedding-ada-002'. Each vector will be assigned an id incrementally starting from 0 and metadata will contain original text.

    texts = ["Some text 1", "Some text 2"]
    insert_response = db.insertFromTexts(texts)
    print(insert_response)
    
  2. Search for a vector from text

    To search for a vector derived from a given text in BagelDB, you can use the searchFromText(text, model='text-embedding-ada-002') method. text is the string for which the corresponding embedding is to be found and searched, and model is optional and defaults to 'text-embedding-ada-002'.

    text = "Some text"
    search_response = db.searchFromText(text)
    print(search_response)
    

These new methods, insertFromTexts and searchFromText, simplify the process of converting text to embeddings and performing operations on BagelDB, providing a higher level of abstraction for users to work with.

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.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

betabageldb-0.1.2-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file betabageldb-0.1.2.tar.gz.

File metadata

  • Download URL: betabageldb-0.1.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for betabageldb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f7774bf0c3e3798cc797feab849bc02ce34773a7d7ca28d01b7ac43cfe3665a1
MD5 b5b2f308cfd75aafc0cce0d50974a495
BLAKE2b-256 f886e379081a2039f53c4b6fd182ca18f9835e66eba970147e21c9f15f00af3f

See more details on using hashes here.

File details

Details for the file betabageldb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: betabageldb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for betabageldb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 194a01d9df268acfc538d66585145c8c71ea4559a26976148c5a5081a0553e34
MD5 8d083a8019158c244aa9a1ea51122e08
BLAKE2b-256 d08ad438f1568d86656786be3d37db953ef88b02ce69b7a937dec3cef4201380

See more details on using hashes here.

Supported by

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