
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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? 🥯💰
To install the BagelDB Python client, run the following command in your terminal:
pip install betabageldb
import uuid
import bagel
from bagel.config import Settings
This snippet imports the required modules for using BagelDB, including the uuid module for generating unique identifiers.
server_settings = Settings(
bagel_api_impl="rest",
bagel_server_host="api.bageldb.ai"
)
Here, we define the settings for connecting to the BagelDB server.
client = bagel.Client(server_settings)
Create an instance of the BagelDB client using the previously defined server settings.
print(client.ping())
This checks the connectivity to the BagelDB server.
print(client.get_version())
Retrieves and prints the version of the BagelDB server.
name = str(uuid.uuid4())
client.create_cluster(name)
client.delete_cluster(name)
Generates a unique name for a cluster, creates it, and then deletes it. This demonstrates basic cluster management.
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)
Creates a cluster or retrieves an existing one, adds documents with metadata. Here ids
are unique identifiers for each documents. BagelDB generates embeddings using its model. And performs a text-based query/search. Here n_results
is to limit number of results.
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)
This is similar to the previous example but uses pre-calculated embeddings for documents and performs a query based on those embeddings.
cluster.modify(name="new_name")
Changes the name of the cluster.
cluster.update(ids=["id1"], metadatas=[{"new":"metadata"}])
Updates the metadata of a specific document in the cluster.
cluster.upsert(documents=["new doc"],
metadatas=[{"new": "metadata"}],
ids=["doc1"])
Inserts or updates documents in the cluster based on provided IDs.
cluster = client.get_or_create_cluster("new_testing")
print(f"cluster size {cluster.cluster_size} mb")
Get the size of the cluster in megabytes. For each cluster max size is 500MB.
In BagelDB we can add image also. Here is an example of adding image to cluster. It supports almost every image format.
filename = "your_img.png"
resp = cluster.add_image(filename)
print(f"Embedding size {cluster.embedding_size}")
Initially, if no data is added to the cluster, the value of embedding_size
is None. After adding data, the embedding_size
is set or assigned.
Multiple images can be added to a BagelDB cluster using URLs. It's recommended to add fewer than 20 images at a time using this function. Upon execution, the function will return the URLs of successfully added images and those that failed. Here's an example:
cluster = api.get_or_create_cluster("new_testing")
urls = [
"https://bagel-public-models-s3-download.s3.eu-north-1.amazonaws.com/cat/60de145c79609acaba3bbe08974a9ff5.jpg",
"https://bagel-public-models-s3-download.s3.eu-north-1.amazonaws.com/cat/black-white-cat-wallpaper.jpg",
]
ids = [str(uuid.uuid4()) for i in range(len(urls))]
resp = cluster.add_image_urls(ids=ids, urls=urls)
Explore additional tutorials for more insights.
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! 🥯👩💻👨💻
FAQs
BagelDB is a Python library for interacting with the BagelDB API.
We found that betabageldb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.