2.0.2 • Published 1 year ago

@relevanceai/sdk v2.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

relevance-js-sdk

Install with npm using:

npm i @relevanceai/sdk

Features

  • Node and Browser support
  • Typescript definitions for almost all relevanceai.com apis
  • Insert millions of documents with one function call
  • Our SearchBuilder makes searching, filtering, and aggregating your data simple

Getting started

Get started by creating an account in cloud.relevanceai.com - select the Vector Database onboarding option. Once set up you can fetch your API key and use the below snippet.

import {VecDBClient,QueryBuilder} from "@relevanceai/sdk";

const discovery = new VecDBClient({
  project: '',
  api_key: '',
  endpoint: ''
});
const dataset = discovery.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' }));

Set up your credentials

Option 1 - Use environment variables

First, set environment variables in your shell before you run your code.

set RELEVANCE_PROJECT to your project name.

set RELEVANCE_API_KEY to your api key. for more information, view the docs here: Authorization docs

Heres a template to copy and paste in for linux environments:

export RELEVANCE_PROJECT=#########
export RELEVANCE_API_KEY=#########

The SDK will use these variables when making api calls. You can then initialise your client like this:

import {VecDBClient} from "@relevanceai/sdk";
const client = new VecDBClient({});

Option 2 - Passing them in code.

import {VecDBClient} from "@relevanceai/sdk";
const client = new VecDBClient({
  project:'########',
  api_key:'########',
});

Examples

You can import builders and type definitions like this

import {QueryBuilder,VecDBClient,BulkInsertOutput} from "@relevanceai/sdk";

Insert millions of items with one function call

const discovery = new VecDBClient({ ... });
const dataset = discovery.dataset('tshirts-prod');
 // Here we create some demo data. Replace this with your real data
const fakeVector = [];
for (let i = 0; i < 768; i++) fakeVector.push(1);
const tshirtsData = [];
for (let i = 0; i < 10000; i++) {
  tshirtsData.push({_id:`tshirt-${i}1`,color:'red',price:i/1000,'title-fake_vector_':fakeVector});
  tshirtsData.push({_id:`tshirt-${i}2`,color:'blue',price:i/1000});
  tshirtsData.push({_id:`tshirt-${i}3`,color:'orange',price:i/1000});
}
const res = await dataset.insertDocuments(tshirtsData,{batchSize:10000});

insertDocuments will output:

{"inserted":30000,"failed_documents":[]}

Text Search and Vector Search

const builder = QueryBuilder();
builder.query('red').text().vector('title-fake_vector_',0.5).minimumRelevance(0.1);
// .text() searches all fields. alternatively, use .text(field1).text(field2)... to search specific fields
const searchResults = await dataset.search(builder);

Filter and retrieve items

const filters = QueryBuilder();
filters.match('color',['blue','red']).range('price',{lessThan:50});
const filteredItems = await dataset.search(filters);

search will output:

{
  results: [
    {
      color: 'red',
      price: 0,
      insert_date_: '2021-11-16T03:14:28.509Z',
      _id: 'tshirt-01',
      _relevance: 0
    }
    ...
  ],
  resultsSize: 10200,
  aggregations: {},
  aggregates: {},
  aggregateStats: {}
}
## Call raw api methods directly
```javascript
const discovery = new VecDBClient({ ... });
const dataset = discovery.dataset('tshirts-prod');
const {body} = await dataset.apiClient.FastSearch({filters:[{match:{key:'_id',value:`tshirt-01`}}]});
expect((body.results[0] as any).color).toBe('red')
2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.145.0

1 year ago

1.141.0

1 year ago

1.149.0

1 year ago

1.126.0

1 year ago

1.134.0

1 year ago

1.130.0

1 year ago

1.138.0

1 year ago

1.144.0

1 year ago

1.140.0

1 year ago

1.129.0

1 year ago

1.148.0

1 year ago

1.133.0

1 year ago

1.137.0

1 year ago

1.143.0

1 year ago

1.128.0

1 year ago

1.147.0

1 year ago

1.132.0

1 year ago

1.136.0

1 year ago

1.142.0

1 year ago

1.146.0

1 year ago

1.127.0

1 year ago

1.131.0

1 year ago

1.139.0

1 year ago

1.135.0

1 year ago

1.98.0

2 years ago

1.79.0

2 years ago

1.94.0

2 years ago

1.90.0

2 years ago

1.122.0

1 year ago

1.82.0

2 years ago

1.107.0

1 year ago

1.63.0

2 years ago

1.86.0

2 years ago

1.103.0

1 year ago

1.67.0

2 years ago

1.111.0

1 year ago

1.119.0

1 year ago

1.70.0

2 years ago

1.115.0

1 year ago

1.74.0

2 years ago

1.97.0

2 years ago

1.93.0

2 years ago

1.121.0

1 year ago

1.60.0

2 years ago

1.106.0

1 year ago

1.83.0

2 years ago

1.125.0

1 year ago

1.64.0

2 years ago

1.102.0

1 year ago

1.87.0

2 years ago

1.68.0

2 years ago

1.110.0

1 year ago

1.71.0

2 years ago

1.118.0

1 year ago

1.75.0

2 years ago

1.114.0

1 year ago

1.96.0

2 years ago

1.92.0

2 years ago

1.120.0

1 year ago

1.101.0

1 year ago

1.80.0

2 years ago

1.109.0

1 year ago

1.84.0

2 years ago

1.61.0

2 years ago

1.124.0

1 year ago

1.105.0

1 year ago

1.65.0

2 years ago

1.89.0

2 years ago

1.88.0

2 years ago

1.69.0

2 years ago

1.117.0

1 year ago

1.72.0

2 years ago

1.113.0

1 year ago

1.76.0

2 years ago

1.99.0

2 years ago

1.78.0

2 years ago

1.95.0

2 years ago

1.91.0

2 years ago

1.100.0

1 year ago

1.123.0

1 year ago

1.108.0

1 year ago

1.81.0

2 years ago

1.62.0

2 years ago

1.104.0

1 year ago

1.85.0

2 years ago

1.66.0

2 years ago

1.112.0

1 year ago

1.73.0

2 years ago

1.116.0

1 year ago

1.77.0

2 years ago

1.56.0

2 years ago

1.37.0

2 years ago

1.58.0

2 years ago

1.35.0

2 years ago

1.39.0

2 years ago

1.40.0

2 years ago

1.42.0

2 years ago

1.44.0

2 years ago

1.46.0

2 years ago

1.25.0

2 years ago

1.48.0

2 years ago

1.29.0

2 years ago

1.27.0

2 years ago

1.51.0

2 years ago

1.53.0

2 years ago

1.32.0

2 years ago

1.55.0

2 years ago

1.30.0

2 years ago

1.57.0

2 years ago

1.36.0

2 years ago

1.59.0

2 years ago

1.34.0

2 years ago

1.38.0

2 years ago

1.41.0

2 years ago

1.43.0

2 years ago

1.45.0

2 years ago

1.26.0

2 years ago

1.47.0

2 years ago

1.49.0

2 years ago

1.28.0

2 years ago

1.50.0

2 years ago

1.52.0

2 years ago

1.33.0

2 years ago

1.54.0

2 years ago

1.31.0

2 years ago

1.15.0

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.19.0

2 years ago

1.18.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.21.0

2 years ago

1.22.0

2 years ago

1.20.0

2 years ago

1.23.0

2 years ago

1.24.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago