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

perkins-db

v0.2.0

Published

A browser-optimized vector database

Downloads

52

Readme

Victor

Web-optimized vector database (written in Rust).

Features

  1. Rust API (using native filesystem, or a transient in-memory filesystem)
  2. Web API (Using the Private Origin File System)
  3. Very efficient vector storage format
    1. For a vector with 1536 dimensions, our representation consumes 1.5 KB, while naively encoding with JSON would consume 20.6 KB.
  4. PCA for vector compression when storage space is low

JS Example

Installation

npm install victor-db

Usage

import { Db } from "victor";

const db = await Db.new();

const content = "My content!";
const tags = ["these", "are", "tags"];
const embedding = new Float64Array(/* your embedding here */);

// write to victor
await db.insert(content, embedding, tags);

// read the 10 closest results from victor that are tagged with "tags"
// (only 1 will be returned because we only inserted one embedding)
const result = await db.search(embedding, ["tags"], 10);
assert(result[0].content == content);

// clear database
await db.clear();

See www/ for a more complete example, including fetching embeddings from OpenAI.

Rust Example

Installation

cargo add victor-db

Usage

use std::path::PathBuf;

use victor_db::native::Db;

let _ = std::fs::create_dir("./victor_test_data");
let mut victor = Db::new(PathBuf::from("./victor_test_data"));

victor.clear_db().await.unwrap();

victor
    .write(
        "Test Vector 1",
        vec![1.0, 0.0, 0.0],
        vec!["Test".to_string()],
    )
    .await;
victor
    .write(
        "Test Vector 2",
        vec![0.0, 1.0, 0.0],
        vec!["Test".to_string()],
    )
    .await;

// read the 10 closest results from victor that are tagged with "tags"
// (only 2 will be returned because we only inserted two embeddings)
let nearest = victor
   .find_nearest_neighbors(vec![0.9, 0.0, 0.0], vec!["Test".to_string()], 10)
   .await
   .first()
   .unwrap()
   .content
   .clone();
assert_eq!(nearest, "Test Vector 1".to_string());

This example is also in the /examples directory. If you've cloned this repository, you can run it with cargo run --example native_filesystem.

Hacking

  1. Victor is written in Rust, and compiled to wasm with wasm-pack.

    Install wasm pack with cargo install wasm-pack or npm i -g wasm-pack (https://rustwasm.github.io/wasm-pack/installer/)

  2. Build Victor with wasm-pack build

  3. Set up the example project, which is in www/.

    If you use nvm, you can just run cd www/ && nvm use

    Then, npm i.

  4. From www/, start the example project with npm run start.

Architecture

Relevant code at src/packed_vector.rs.

Packed vector storage explanation


File structure explanation

Us

Sam Hall

Andre Popovitch