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:
-
Import the
BagelDBclientStart by importing the
BagelDBclient into your Python script.from BagelDB import BagelDB
-
Initialize the BagelDB client
Next, initialize a new instance of the
BagelDBclient. Make sure you have your OpenAI API key set in your environment variables asOPENAI_API_KEY.db = BagelDB()
-
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)
-
Get OpenAI embeddings
Use the
getOpenAIEmbedding(inputText, model='text-embedding-ada-002')method to get embeddings from OpenAI. TheinputTextis the text for which embeddings are required.modelis optional and defaults to 'text-embedding-ada-002'.input_text = "Some text" embeddings = db.getOpenAIEmbedding(input_text) print(embeddings)
-
Insert vectors into BagelDB
To insert vectors into a given index in BagelDB, use the
insert(index, vectors)method.indexis the index in which vectors are to be inserted, andvectorsis 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)
-
Search for a vector in BagelDB
To search for a vector in a given index in BagelDB, use the
search(index, vector)method.indexis the index in which the search is to be performed, andvectoris 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bageldb-beta-0.1.0.tar.gz.
File metadata
- Download URL: bageldb-beta-0.1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94b04e8f2ff28ab6afe24033deff1a6e645197d8848f352866e9bfc03b604216
|
|
| MD5 |
bdc5edc04a1b40bf059236392cf7016e
|
|
| BLAKE2b-256 |
df83a99a8bf141223d5b1215c11bcf81255596a154f7306c1958ae957d4288bd
|
File details
Details for the file bageldb_beta-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bageldb_beta-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c86c6adf8c6d3787ccb383ee81ecb6596bcf31226ef2171e6edea9b2bceb72e
|
|
| MD5 |
b8bf52d75ddad9df50a9bee0c8101600
|
|
| BLAKE2b-256 |
9ca4372eb246b3e8a2b95472a9462e6ec96a9613600d83aeef0165377a4bb981
|