npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@relevanceai/dataset

v2.1.0

Published

Javascript client for RelevanceAI APIs. Browser, Node.js and typescript support.

Downloads

3

Readme

relevance-js-sdk

Install with npm using:

npm i @relevanceai/dataset

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 {Client,QueryBuilder} from "@relevanceai/dataset";

const discovery = new Client({
  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 {Client} from "@relevanceai/dataset";
const client = new Client({});

Option 2 - Passing them in code.

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

Examples

You can import builders and type definitions like this

import {QueryBuilder,Client,BulkInsertOutput} from "@relevanceai/dataset";

Insert millions of items with one function call

const discovery = new Client({ ... });
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 Client({ ... });
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')