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.
-
Import the
BagelDBclientStart by importing the
BagelDBclient into your Python script.from betabageldb import BagelDB
-
Initialize the BagelDB client
Initialize a new instance of the
BagelDBclient. 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 asOPENAI_API_KEY.index = "myIndex" db = BagelDB(index)
-
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 BagelDB, use the
insert(vectors)method.vectorsis 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)
-
Search for a vector in BagelDB
To search for a vector in BagelDB, use the
search(vector)method.vectoris 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.
-
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. Thetextsparameter is a list of strings for which embeddings are required, andmodelis 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)
-
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.textis the string for which the corresponding embedding is to be found and searched, andmodelis 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7774bf0c3e3798cc797feab849bc02ce34773a7d7ca28d01b7ac43cfe3665a1
|
|
| MD5 |
b5b2f308cfd75aafc0cce0d50974a495
|
|
| BLAKE2b-256 |
f886e379081a2039f53c4b6fd182ca18f9835e66eba970147e21c9f15f00af3f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
194a01d9df268acfc538d66585145c8c71ea4559a26976148c5a5081a0553e34
|
|
| MD5 |
8d083a8019158c244aa9a1ea51122e08
|
|
| BLAKE2b-256 |
d08ad438f1568d86656786be3d37db953ef88b02ce69b7a937dec3cef4201380
|