This document is generated from the OasisDBClient class implemented in client.py. It lists all public methods and explains how to use them so that developers can get started quickly.
from client import OasisDBClient
client = OasisDBClient()
print(client.health_check()) # Should print True when the server is reachableOasisDBClient(
base_url: str = "http://localhost:8080",
*,
session: Optional[requests.Session] = None,
timeout: Optional[float | tuple[float, float]] = 30,
)Parameter description:
| Parameter | Type | Default | Description |
|---|---|---|---|
base_url |
str |
"http://localhost:8080" |
Root URL of the OasisDB HTTP service |
session |
requests.Session | None |
None |
Optional shared HTTP session |
timeout |
float | (float, float) | None |
30 |
Request timeout in seconds; pass None for no limit |
| Method | Return | Description |
|---|---|---|
health_check() |
bool |
Check whether the server is alive |
create_collection(name, dimension, *, index_type="hnsw", parameters=None) |
dict |
Create a vector collection |
get_collection(name) |
dict |
Get collection details |
list_collections() |
list[dict] |
List all collections |
delete_collection(name) |
None |
Delete a collection |
upsert_document(collection, *, doc_id, vector, parameters=None) |
dict |
Insert or update a single document |
batch_upsert_documents(collection, documents) |
None |
Insert/update multiple documents |
get_document(collection, doc_id) |
dict |
Get a single document |
delete_document(collection, doc_id) |
None |
Delete a single document |
build_index(collection, documents) |
None |
Build index offline |
set_params(collection, parameters) |
None |
Adjust index/search parameters |
search_vectors(collection, vector, *, limit=10) |
dict |
Return vector-only nearest-neighbor results |
search_documents(collection, vector, *, limit=10, filter=None) |
dict |
Return document results with optional filter |
Detailed explanations, parameters and examples for each method are provided below.
- HTTP call:
GET / - Return:
Trueif the server returns{"status": "ok"}.
client.health_check() # True / Falsecreate_collection(
name: str,
dimension: int,
*,
index_type: str = "hnsw",
parameters: Mapping[str, str] | None = None,
) -> dictExplanation:
name: collection name, unique.dimension: vector dimension.index_type: index type, currently supports"hnsw".parameters: index-specific parameter dictionary.
Example:
client.create_collection("movies", 768, index_type="hnsw", parameters={"efConstruction": "200"})get_collection(name):GET /v1/collections/{name}list_collections():GET /v1/collectionsdelete_collection(name):DELETE /v1/collections/{name}
info = client.get_collection("movies")
all_cols = client.list_collections()
client.delete_collection("movies")upsert_document(
collection: str,
*,
doc_id: str,
vector: Sequence[float],
parameters: Mapping[str, Any] | None = None,
) -> dictInsert or update a single document in the specified collection.
Example:
client.upsert_document(
"movies",
doc_id="tt0111161",
vector=[0.12, 0.98, ...],
parameters={"title": "The Shawshank Redemption"},
)batch_upsert_documents(collection: str, documents: Iterable[Mapping[str, Any]]) -> NoneInsert or update multiple documents at once. Each element in documents must contain id and vector; other fields are optional.
get_document(collection, doc_id):GET /v1/collections/{collection}/documents/{id}delete_document(collection, doc_id):DELETE /v1/collections/{collection}/documents/{id}
build_index(collection: str, documents: Iterable[Mapping[str, Any]]) -> NoneBuild the index on the server side offline; useful when you import a large dataset and then build the index in one shot.
set_params(collection: str, parameters: Mapping[str, Any]) -> NoneSet runtime search or index parameters (e.g. {"efsearch": 128}) for the specified collection.
Example:
client.set_params("movies", {"efsearch": 128})search_vectors(collection: str, vector: Sequence[float], *, limit: int = 10) -> dictReturn only similarity scores of vectors without document metadata.
search_documents(
collection: str,
vector: Sequence[float],
*,
limit: int = 10,
filter: Mapping[str, Any] | None = None,
) -> dictReturn matching documents and scores. You can pass a filter in JSON-Schema style to refine results.
Example:
results = client.search_documents(
"movies",
query_vector,
limit=5,
filter={"genre": "Drama"},
)
for hit in results["hits"]:
print(hit["id"], hit["score"])All methods raise OasisDBError when the server returns 4xx or 5xx.
from client import OasisDBError
try:
client.get_collection("non-exist")
except OasisDBError as e:
print(e.status_code, str(e))OasisDBClient implements the context-manager protocol, so you can use with to ensure the HTTP connection is closed properly:
with OasisDBClient() as client:
client.create_collection("demo", 128)That’s all! You now know every public API in the Python SDK—happy vectorizing!