跳到主要内容
Voy 是一个用 Rust 编写的 WASM 向量相似性搜索引擎。它支持非 Node 环境,如浏览器。您可以将 Voy 作为 LangChain.js 的向量存储。

安装 Voy

有关安装 LangChain 软件包的一般说明,请参阅此部分
npm
npm install @langchain/openai voy-search @langchain/community @langchain/core

用法

import { VoyVectorStore } from "@langchain/community/vectorstores/voy";
import { Voy as VoyClient } from "voy-search";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";

// Create Voy client using the library.
const voyClient = new VoyClient();
// Create embeddings
const embeddings = new OpenAIEmbeddings();
// Create the Voy store.
const store = new VoyVectorStore(voyClient, embeddings);

// Add two documents with some metadata.
await store.addDocuments([
  new Document({
    pageContent: "How has life been treating you?",
    metadata: {
      foo: "Mike",
    },
  }),
  new Document({
    pageContent: "And I took it personally...",
    metadata: {
      foo: "Testing",
    },
  }),
]);

const model = new OpenAIEmbeddings();
const query = await model.embedQuery("And I took it personally");

// Perform a similarity search.
const resultsWithScore = await store.similaritySearchVectorWithScore(query, 1);

// Print the results.
console.log(JSON.stringify(resultsWithScore, null, 2));
/*
  [
    [
      {
        "pageContent": "And I took it personally...",
        "metadata": {
          "foo": "Testing"
        }
      },
      0
    ]
  ]
*/

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.