Reference
Use our SDK for querying your datasets
Install the dataset SDK:
npm install --save @relevanceai/dataset
Quickstart
Import the dataset SDK and create the client.
import { Client, QueryBuilder } from '@relevanceai/dataset';
const client = new Client({
project: '',
api_key: '',
endpoint: '',
});
Create a dataset object and run insert documents and search.
const dataset = client.dataset('1000-movies');
const movies = [{ title: 'Lord of the Rings: The Fellowship of the Ring', grenre: 'action', budget: 100 }, ...]
await dataset.insertDocuments(movies, [{ model_name: 'text-embedding-ada-002', field: 'title' }]);
const {results} = await dataset.search(QueryBuilder().vector('title_vector_', { query: 'LOTR', model: 'text-embeddings-ada-002' }));
Methods
createIfNotExist
The createIfNotExist
method is used to create a dataset if it doesn’t exist.
createIfNotExist(): Promise<Boolean>
recreateIfExists
The recreateIfExists
method is used to recreate a dataset if it exists.
recreateIfExists(): Promise<Boolean>
insertDocuments
The insertDocuments
method is used to insert documents into the dataset. It takes in a list of documents and a list of vectorization options.
insertDocuments(documents: array[object], vectorizationOptions?: array[object], options?: Options): Promise<BulkInsertOutput>
search
The search
method is used to search the dataset. It takes in a query builder object.
search(queryBuilder: QueryBuilder, options?: Options): Promise<SearchOutput>
updateDocuments
The updateDocuments
method is used to update documents in the dataset. It takes in a list of documents.
updateDocuments(documents: array[object], options?: Options): Promise<BulkUpdateOutput>
updateDocumentsWhere
The updateDocumentsWhere
method is used to update documents in the dataset based on a filter. It takes in a filter and a list of documents.
updateDocumentsWhere(filter: QueryBuilder, partialUpdates: array[object], options?: Options): Promise<BulkUpdateOutput>
getDocument
The getDocument
method is used to get a document from the dataset. It takes in a document id.
getDocument(id: string): Promise<GetDocumentOutput>
deleteDocument
The deleteDocument
method is used to delete a document from the dataset. It takes in a document id.
deleteDocument(id: string): Promise<DeleteDocumentOutput>
deleteDocumentsWhere
The deleteDocumentsWhere
method is used to delete documents from the dataset based on a filter. It takes in a filter.
deleteDocumentsWhere(filter: QueryBuilder): Promise<DeleteDocumentsOutput>
QueryBuilder
The query builder is used to construct queries for searching the dataset. It is a chainable API that allows you to build complex queries with a simple syntax.
To use it, start with QueryBuilder()
and chain it with the following methods to generate the query.
Vector
The vector
method is used to search for documents based on a vector. It takes in a field name and a vector object.
vector(field: string, options: { query?: string, model?: enum, vector?: array[double] }): QueryBuilder
Example:
QueryBuilder().vector('title_vector_', {
query: 'LOTR',
model: 'text-embeddings-ada-002',
});
Sort
The sort
method is used to sort the results based on a field. It takes in a field name and a sort order.
sort(field: string, direction: enum): QueryBuilder
Example:
QueryBuilder().sort('budget', 'asc');
Page
The page
method is used to paginate the results. It takes in a page number.
page(page: number): QueryBuilder
Example:
QueryBuilder().page(2);
Page size
The pageSize
method is used to set the page size. It takes in a page size.
pageSize(pageSize: number): QueryBuilder
Example:
QueryBuilder().pageSize(10);
Include fields
The includeFields
method is used to include fields in the results. It takes in a list of field names.
includeFields(fields: array[string]): QueryBuilder
Example:
QueryBuilder().includeFields(['title', 'budget']);
Was this page helpful?