PIRAMID

Python client

The piramid package, a typed client for the HTTP API.

pip install piramid

The package talks to a running server; it does not include the engine. Python 3.9 or newer.

from piramid import Piramid

db = Piramid("http://localhost:6333")  # api_key=..., or PIRAMID_API_KEY

db.embed("notes", ["first", "second"], metadata=[{"topic": "a"}, {"topic": "b"}])
hits = db.search_text("notes", "crash safety", k=5, filter={"topic": {"eq": "a"}})

answer = db.generate(
    messages=[{"role": "user", "content": "What happens to deleted documents?"}],
    collection="notes",
    k=2,
    max_new_tokens=128,
)
print(answer["text"])

Streaming

stream yields one retrieval event, a token event per token, then done:

for event in db.stream(prompt="Summarise the notes.", collection="notes"):
    if event["event"] == "token":
        print(event["data"]["text"], end="", flush=True)

Methods

MethodWhat it does
health, version, modelserver state
collections, create_collection, collection, delete_collection, count, compactcollections
embedembed texts with the server's provider and store them
insert, upsertstore vectors computed by the caller
get, list, deletedocuments by id
search, search_textexact search by vectors or by text
generate, streamgeneration, with retrieval when collection is given

A non-2xx response raises PiramidError, carrying the server's message and the HTTP status.

On this page