Search with the Python SDK
client.search: the passages that answer a question, with the file and place of each.
client.search sends the request of Search and returns its response, typed. The fields are the API's, as keyword arguments.
from byterover import ByteRover
client = ByteRover()
found = client.search(
query="Which policy section covers EU refunds?",
drive_ids=["drv_4h7k2m9q8r1t5v6w3x0y"],
effort="medium",
)effort has no default; medium suits most questions. See Search effort.
Narrow the search
folder covers a folder and everything under it. filters narrows by tag, file type and date, and every filter you set must match. See Filters.
contracts = client.search(
query="Which contracts renew automatically, and what notice do they need?",
drive_ids=["drv_4h7k2m9q8r1t5v6w3x0y"],
effort="high",
folder="/legal",
filters={"tags": ["legal", "signed"], "file_type": ["pdf", "docx"], "updated_after": "2026-01-01"},
group_by_document=False,
)group_by_document=False lets several passages come from the same document. By default each comes from a different one.
Show the source
Each result is a passage. Its file is in documents, under the same document_id, so a citation can name the file, the page and the headings.
files = {document.document_id: document for document in found.documents}
for result in found.results:
file = files.get(result.document_id)
page = "" if result.location.page is None else f", page {result.location.page}"
print(f"{file.name if file else 'A deleted file'}{page}, {' > '.join(result.location.heading_path)}")
print(result.text)A file deleted after it was indexed has no entry in documents, though its results still come back.
To read more around a passage, pass its document_id to client.documents.read, with one selector from its location, such as page=result.location.page or heading_path=result.location.heading_path. See Documents and folders.
Time and price
A search waits up to 105 seconds at medium and 135 seconds at high; pass timeout to change that. A search is charged once it runs, so the SDK never sends it again when its outcome is unknown: after a timeout, a lost connection or a 5xx, you get the error and decide. A search that was refused before it started, with a 429 from ByteRover or a connection that never opened, is retried.
from byterover import APIConnectionError, RateLimitError
try:
client.search(query="Refund window", drive_ids=["drv_4h7k2m9q8r1t5v6w3x0y"], effort="medium", timeout=60)
except RateLimitError:
print("Still limited after the retries.")
except APIConnectionError as error:
if error.sent != "unknown":
raise
print("It may have run, and been charged.")When nothing answers
Search ranks passages; it doesn't decide whether they answer the question. You get an empty results list only when nothing in the drives comes close. See Results.