@silvermine/quarry
v0.3.2
Published
Node.js binding for Quarry, a serverless hybrid search engine that keeps its index in object storage
Keywords
Readme
quarry-node
A Node.js binding for Quarry: the npm package @silvermine/quarry. It gives a JavaScript
or TypeScript host the producer API and the
engine's entry points. The package also contains
lambda/bootstrap, the Lambda hosts built for
Linux x64, so one package supplies a deployment's Node.js functions and its build and task
functions.
cd crates/quarry-node
npm run build -- --linux
npm test
npm packnpm run build builds the binding for this machine. With --linux, it also builds the
binding and lambda/bootstrap for Linux x64 with cargo zigbuild. Install zig and
cargo-zigbuild first, and add the Rust target x86_64-unknown-linux-gnu. The package
contains one .node file for each platform, and index.js loads the file for the
platform it runs on: macOS on arm64, or Linux on x64 with glibc 2.28 or later. Git ignores
every file that the build makes, and npm pack stops when one of them is not there or is
older than the source.
Use
npm install @silvermine/quarryconst { open } = require('@silvermine/quarry');
const quarry = await open({ durableBucket: 'my-durable', servingBucket: 'my-serving--use1-az4--x-s3' });
const transaction = await quarry.beginReplace('articles', { schema });
await transaction.upsert({
id: 'article-48112',
fields: { title: { exact: [ 'storm', 'closes', 'harbor', 'bridge' ] } },
stored: { title: 'Storm Closes Harbor Bridge' },
});
const commitId = await transaction.commit();
await quarry.build('articles');
await quarry.status('articles', commitId); // { state: 'applied', epoch: 1 }
const response = await quarry.search({ index: 'articles', tokens: { exact: [ 'harbor' ] } });index.d.ts declares every function, option, and error code.
- One
Quarryfor each process.openmakes one engine, with its memory cache, and one producer. Call it one time and keep the result. AQuarryreads the list of epochs again only after the index'srefreshSeconds, as each query worker does. - Stores.
durableBucketandservingBucketselect the S3 adapters, with the credentials and the region of the environment.dataDirectoryselects two local folders, as thequarrycommand does. The binding has no allow list, so the host selects the buckets. - A process that only searches.
readOnlyServingmakes the binding request read-only sessions on the serving bucket. Thenbuildandgcreject. - JSON. Documents, schemas, requests, responses, and records are the JSON that the Quarry documents specify. The binding sends them to Rust as text and does not rename a field.
- Errors. Each failure rejects with an
Error. Itsmessageis Quarry's text, and itscodeis the kind of failure:InvalidRequestfor a document or a request that Quarry refuses,NotFound,CorruptData,Otherfor storage and all other failures, andInvalidArgfor an argument that the binding refuses. - Transactions. An invalid document rejects, and the transaction stays open without
it. Await each call before the next call. After
commit, the transaction is closed. - Shared transactions.
share,join,finish, andcommitSharedlet several processes write one transaction, such as a replace that loads a whole index (see shared transactions). - Build and garbage collection.
buildandgcrun in the process, on a thread of their own, in thesinglerebuild mode. A function host with a time limit uses the build host inlambda/bootstrapfor rebuilds and merges.
On AWS Lambda
Quarry on AWS Lambda tells how a function sets up the memory cache, the disk cache, and the local replica, how it keeps copies running after each response, and which indexes it copies at start.
