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

vectordb-js

v1.0.1

Published

用typescript实现的vector db

Downloads

37

Readme

vertor store

用typescript实现的vector db

为什么会有这个东西呢? 因为在做公司内部的文档机器人的时候,我悲剧的发现内部npm没有langchain 因此只能蛋疼的手搓一个vector store以供迁移

优势

在公司的开发中,如果要引入GPT等工具做增效工具,我们不可避免地需要考虑信安等因素

大部分公司的解决方案都是内部封装一个GPT的api,由信安部门做过滤

但是当我们使用这种api搭建基于vector db的文档机器人这类的产品时,就会遇到一个问题,那就是目前流行的提供此类功能的工具库大多是高度集成的(此处点名langchain),这意味着我们很难把其内部调用的api换成公司内部的api

本项目提出的背景也是基于此,本项目将获取embedding与构建vector store剥离开来,方便受限情况下的文档机器人的搭建

使用

  1. npm i vectordb-js
  2. 接入自己编写的获取openai embedding结果的函数,以azure openai版本为例:
    import { vectorStore } from "vectordb-js";
     import { OpenAIClient, AzureKeyCredential } from "@azure/openai";
     import { ISplitedDocument,IVector } from "./types";
     require("dotenv").config();
    
     const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "";
     const azureApiKey = process.env.AZURE_OPENAI_KEY || "";
    
     const DOC_PATH = "documents";
    
     const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
     const deploymentId = "thy-openai-embedding";
    
     async function openaiEmbedding(
         splitDocs: ISplitedDocument[]
     ): Promise<IVector[]> {
         const res = await client.getEmbeddings(
             deploymentId,
             splitDocs.map((doc) => doc.content)
         );
         const vectors: IVector[] = res.data.map((vector, idx) => {
             return {
                 embedding: vector.embedding,
                 metadata: {
                     path: splitDocs[idx].metaData.path,
                     startIndex: splitDocs[idx].metaData.startIndex,
                     endIndex: splitDocs[idx].metaData.endIndex,
                 },
             };
         });
         return vectors;
     }
    
     async function main(queryQuestion: string) {
     const openaiVectorStore = await vectorStore({
         docPath: DOC_PATH,
         embeddingFunc: openaiEmbedding,
     });
     const inputQuery = await client.getEmbeddings(deploymentId, [
         queryQuestion,
     ]);
    
     const queryVector = inputQuery.data[0].embedding;
     const res2 = openaiVectorStore.query(queryVector, 2);
    
     console.log(res2);
     }
    
     main("线程与进程的区别是什么?");