BagelDB is a Python library for interacting with the BagelDB API.
Project description
BagelDB Python Client 🥯
Welcome to the BagelDB Python Client Example! BagelDB is your bread-and-butter library for interacting with the BagelDB API without breaking a sweat.
One of the perks? No need to call the OpenAI Embeddings method or any other model to generate embeddings! That's right, the BagelDB client handles that for you. So, you don't need to spend extra bucks on generating embeddings. Quite a dough-saver, isn't it? 🥯💰
Prerequisites
- Python 3.6+
- pip package manager
- BagelDB account and API key
Installation
To install the BagelDB Python client, run the following command in your terminal:
pip install betabageldb
Usage
- Import the necessary modules:
import uuid
import bagel
from bagel.config import Settings
- Define the BagelDB server settings:
server_settings = Settings(
bagel_api_impl="rest",
bagel_server_host="api.bageldb.ai"
)
- Create the BagelDB client:
client = bagel.Client(server_settings)
- Ping the BagelDB server:
print(client.ping())
- Get the BagelDB server version:
print(client.get_version())
- Create and delete a cluster:
name = str(uuid.uuid4())
client.create_cluster(name)
client.delete_cluster(name)
- Create, add documents, and query a cluster:
cluster = client.get_or_create_cluster("testing")
cluster.add(
documents=["This is doc", "This is gooogle doc"],
metadatas=[{"source": "notion"},
{"source": "google-doc"}],
ids=[str(uuid.uuid4()), str(uuid.uuid4())],
)
results = cluster.find(query_texts=["query"], n_results=5)
- Add embeddings and query (without needing to generate embeddings yourself!):
cluster = client.get_or_create_cluster("new_testing")
cluster.add(embeddings=[[1.1, 2.3], [4.5, 6.9]],
metadatas=[{"info": "M1"}, {"info": "M1"}],
documents=["doc1", "doc2"],
ids=["id1", "id2"])
results = cluster.find(query_embeddings=[[1.1, 2.3]], n_results=2)
- Modify cluster name:
cluster.modify(name="new_name")
- Update document metadata:
cluster.update(ids=["id1"], metadatas=[{"new":"metadata"}])
- Upsert documents:
cluster.upsert(documents=["new doc"],
metadatas=[{"new": "metadata"}],
ids=["doc1"])
Need more dough-tails? See the example code for a more comprehensive guide on using the BagelDB Python client.
Happy coding and enjoy your fresh Bagels! 🥯👩💻👨💻
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
Hashes for betabageldb-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c46704ed1cfd1d409d24e949e1bbf8286c6d7c16ef6e407235777be16b710d8 |
|
MD5 | 2e0cfe627ac46a27fa1089088353c253 |
|
BLAKE2b-256 | fd6361e4ac7f6a0394534ac087d74553f773259ca5e3eb1fcd9b6ce8271f4590 |