Pre-release (preview). This SDK is published as a preview of Loams. Its API can change between previews without notice: pin the exact version, and expect breaking changes until 1.0. Report problems at https://github.com/ostrium-labs/loams/issues.
composer require loams/loams:0.1.3These instructions target the released 0.1.3 package and matching source tag.
The package is loams/loams on Packagist. Composer has no preview stability,
so a prerelease such as v0.1.0-preview.2 is tagged v0.1.0-alpha.2 there, and
a project whose minimum-stability is stable must name it exactly (or add
@alpha). It needs PHP 8.2 or newer.
Packagist reads the read-only split repository
ostrium-labs/loams-php, which
sdk-release.yml updates from this directory on each release. Send changes here,
to sdks/php in ostrium-labs/loams, not to the split repository.
<?php
require 'vendor/autoload.php';
$client = new Loams\Client('https://acme.loams.dev');Runnable service examples (quickstart, approvals, status) and the SDK app tour in
examples/ use the published 0.1.3 SDK. The notes app is the full
app-module example; it keeps the instance/approval/device samples intact.
The app-building modules are namespaces(), collections(), documents(),
search(), vector(), graph() (experimental), sql() and streams(), with
the Schema, Filter and Search builders in Loams\Builders.
examples/notes/notes.php is the whole flow:
use Loams\Builders\{Filter, Fusion, Schema, Search};
use Loams\Client;
// LOAMS_ENDPOINT, LOAMS_API_KEY (or LOAMS_TOKEN) and LOAMS_NAMESPACE.
$client = Client::fromEnv(sessionConsistency: true);
// or: new Client('http://127.0.0.1:8080', apiKey: '…', namespace: 'app', timeout: 30.0)
$client->namespaces()->create('app');
$client->collections()->create('notes', Schema::new()
->keyword('title')->text('body')->keyword('tags')->i64('n')->vector('embedding', 4));
$notes = $client->collection('notes');
$notes->upsert([['id' => 1, 'source' => ['title' => 'Refunds', 'body' => 'refund policy', 'tags' => ['policy'], 'n' => 1],
'vectors' => ['embedding' => [1, 0, 0, 0]]]]);
$hits = $notes->search(Search::on('notes')
->text('refund', ['body'])
->vector('embedding', [1, 0, 0, 0])
->fuse(Fusion::rrf(60)) // or Fusion::dbsf(), Fusion::weighted(0.7, 0.3)
->filter(Filter::and(Filter::eq('tags', 'policy'), Filter::range('n', gte: 1)))
->highlight('body')
->select(include: ['title'])
->limit(10))['hits'];- Answers are proto3 JSON arrays (
lowerCamelCasekeys; 64-bit integers as strings).Loams\Values::fromDocumentId($hit['pk'])gives a key back as an int or a string. - Writes.
documents()->upsert,delete,patchandwrite(raw ops) answer a consistencytoken.writeBatch($collection, $iterable, chunkRows:, chunkBytes:)sends chunks one at a time, each with its own idempotency key, and returns aLoams\BatchResult(the mergedtoken,chunks,rows); a failed chunk throwsLoams\BatchExceptionwithchunksAppliedand thetokenof the chunks before it. - Reads.
documents()->get,count,scroll/scrollAll(aGenerator),search()->query,queryAll(followssearchAfter; the sort must end withSort::pk()),text($collection, $text, $fields),hybrid($collection, $text, $vector, $field, $fields, $fusion)andvector()->search($collection, $vector, $field). Each takesconsistency:('strong','eventual'or a token). WithsessionConsistency: trueevery token an answer carries is merged into the session and attached to later reads. - Graph (experimental):
graph()->create,query(GQL with PHP parameters),queryBatch,explain,listAll,delete;Loams\Modules\Graph::records($res)gives rows as arrays. - The default namespace fills every request that names none; with neither,
the call throws
Loams\InvalidArgumentExceptionbefore any network call. Timeouts default to 30 s per unary call (timeout:on the client,options: ['timeout' => …]per call,nullfor none); a spent budget throwsLoams\DeadlineExceededExceptionwith reasonclient_deadline_exceededand is never retried. Every call takesoptions: ['idempotencyKey' => …]too. - SQL.
sql()->query($sql, [$1, …], maxRows:, consistency:)answerscolumnsandrows;Loams\Modules\Sql::records($res)gives rows as arrays.queryArrowanswers the Arrow IPC bytes. SQL reads see the session's collection writes. - Streams.
streams()->create,get,list/listAll,produce($stream, $records, partition:, producerId:, producerSeq:)(a record is a string, an array sent as JSON, or['key' => …, 'value' => …, 'headers' => […]]; a repeated producer sequence is deduplicated),fetch(Streams::records($res)decodes it),produceEvents/fetchEvents(CloudEvents as arrays), andsubscribe($stream, partition:, fromOffset:), aSubscriptionto iterate,cancel()and resume fromoffset(). - Durable execution has no module: use a Resonate SDK with
LOAMS_ENDPOINT/durable/as its URL.
composer install
vendor/bin/phpunit
LOAMS_TEST_ENDPOINT=http://127.0.0.1:8080 vendor/bin/phpunit # plus the app scenario against `loams dev`Licensed under Apache-2.0 (see LICENSE).