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

dria

v0.0.4

Published

<p align="center"> <img src="https://raw.githubusercontent.com/firstbatchxyz/dria-js-client/master/logo.svg" alt="logo" width="142"> </p>

Downloads

2,172

Readme

DriaJS client is a library & CLI that integrates Dria to your application, providing a convenient interface to harness the capabilities of Dria's vector search and retrieval services.

  • [x] Create & manage your knowledge bases on Dria.
  • [x] Make vector based queries, text based searches or fetch vectors by their IDs.
  • [x] Insert vectors & texts to your existing knowledge.
  • [x] Integrated into LangChainJS.

Installation

Install Dria from NPM:

npm  install dria
yarn add dria
pnpm add dria
bun  add dria

Usage

To begin, import Dria to your code:

import Dria from "dria";

Queries

With Dria, you can connect to an existing knowledge uploaded to Dria by providing its contract ID. You can then ask questions to this knowledge, make vector based queries, or directly fetch embeddings with their IDs.

const dria = new Dria({ apiKey, contractId });

// a text-based search
const searchRes = await dria.search("What is the capital of France?");

// a vector-based query
const queryRes = await dria.query([0.1, 0.2, 0.3]);

// fetch data for specific ids
const queryRes = await dria.fetch([0, 1, 2]);

[!TIP]

You can omit the apiKey, in which case Dria will look for it at DRIA_API_KEY environment variable.

Inserting Data

You can insert new data to your existing knowledge, either as batch of texts with metadata or vectors with metadata.

const dria = new Dria({ apiKey, contractId });

// insert raw text, which will be converted to vector embeddings
// with respect to the model used by this contract
const insertTextRes = await dria.insertTexts([
  { text: "I am a text.", metadata: { fromReadme: true } },
  { text: "I am another text.", metadata: { fromReadme: true } },
]);

// or, compute embeddings on your own and insert the vectors
const insertTextRes = await dria.insertTexts([
  { vector: [0.1, 0.2, 0.3], metadata: { fromReadme: true } },
  { vector: [0.3, 0.2, 0.1], metadata: { fromReadme: true } },
]);

Creating a Knowledge

A new knowledge can be created with Dria client as well. In this example, we omit the contractId that was provided to the constructor, since we don't have a contract yet. After deploying a contract, we will set that field manually and we will then be able to call all functions described above so far!

const dria = new Dria({ apiKey });

contractId = await dria.create(
  "My New Contract,
  "jina-embeddings-v2-base-en",
  "Science",
);
dria.contractId = contractId;

Our client supports a variety of text embedding models by default:

  • OpenAI's Text Embeddings-2 Ada (text-embedding-ada-002)
  • OpenAI's Text Embeddings-3 Small (text-embedding-3-large)
  • OpenAI's Text Embeddings-3 Large (text-embedding-ada-002)
  • Jina's Embeddings V2 Base EN (jina-embeddings-v2-base-en)
  • Jina's Embeddings V2 Small EN (jina-embeddings-v2-small-en)

[!WARNING]

If you provide a different embedding model when creating a contract, you are expected to use those same embeddings models to create vectors from text queries, and call the query method.

Metadata Types

Each knowledge may have a different metadata type, based on the content they were created from. For example, a CSV knowledge will have each column as a separate field in the metadata. You can provide the metadata type as a template parameter so that all methods are type-safe:

type MetadataType = { id: number; foo: string; bar: boolean };
const dria = new Dria<MetadataType>();

// metadata is typed as given above
const res = dria.fetch([0]);

Metadata type can be overridden for each method as well, if the need may be:

const res = dria.fetch<{ page: number; source: string }>([0]);

Examples

You can check out some examples:

  • Simple: Query a knowledge directly.
  • Langchain: Use Dria retriever in an AI agent of LangChain.

Building

You can build the library for NPM via:

bun run build
bun b # alias

We are using Bun's own bundler.

[!NOTE]

The protobuf files are included in the repo, but they can be generated again via:

bun proto

Testing

For the tests, you will need an API key at DRIA_API_KEY environment variable, which you can provide in an .env.test file. You can run tests via:

bun run test
bun t # alias

You can also specify the test titles (as they appear in describe, it or test).

bun t -t "test-name"