跳至主要内容

Tigris

Tigris 使得使用向量嵌入构建 AI 应用程序变得容易。它是一个完全托管的云原生数据库,允许您存储和索引文档和向量嵌入,以实现快速且可扩展的向量搜索。

兼容性

仅适用于 Node.js。

设置

1. 安装 Tigris SDK

按照以下方式安装 SDK

npm install -S @tigrisdata/vector

2. 获取 Tigris API 凭据

您可以 在此 注册免费的 Tigris 帐户。

注册 Tigris 帐户后,创建一个名为 vectordemo 的新项目。接下来,记下 clientIdclientSecret,您可以在项目的应用程序密钥部分获取它们。

索引文档

npm install -S @langchain/openai
import { VectorDocumentStore } from "@tigrisdata/vector";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "@langchain/openai";
import { TigrisVectorStore } from "langchain/vectorstores/tigris";

const index = new VectorDocumentStore({
connection: {
serverUrl: "api.preview.tigrisdata.cloud",
projectName: process.env.TIGRIS_PROJECT,
clientId: process.env.TIGRIS_CLIENT_ID,
clientSecret: process.env.TIGRIS_CLIENT_SECRET,
},
indexName: "examples_index",
numDimensions: 1536, // match the OpenAI embedding size
});

const docs = [
new Document({
metadata: { foo: "bar" },
pageContent: "tigris is a cloud-native vector db",
}),
new Document({
metadata: { foo: "bar" },
pageContent: "the quick brown fox jumped over the lazy dog",
}),
new Document({
metadata: { baz: "qux" },
pageContent: "lorem ipsum dolor sit amet",
}),
new Document({
metadata: { baz: "qux" },
pageContent: "tigris is a river",
}),
];

await TigrisVectorStore.fromDocuments(docs, new OpenAIEmbeddings(), { index });

查询文档

import { VectorDocumentStore } from "@tigrisdata/vector";
import { OpenAIEmbeddings } from "@langchain/openai";
import { TigrisVectorStore } from "langchain/vectorstores/tigris";

const index = new VectorDocumentStore({
connection: {
serverUrl: "api.preview.tigrisdata.cloud",
projectName: process.env.TIGRIS_PROJECT,
clientId: process.env.TIGRIS_CLIENT_ID,
clientSecret: process.env.TIGRIS_CLIENT_SECRET,
},
indexName: "examples_index",
numDimensions: 1536, // match the OpenAI embedding size
});

const vectorStore = await TigrisVectorStore.fromExistingIndex(
new OpenAIEmbeddings(),
{ index }
);

/* Search the vector DB independently with metadata filters */
const results = await vectorStore.similaritySearch("tigris", 1, {
"metadata.foo": "bar",
});
console.log(JSON.stringify(results, null, 2));
/*
[
Document {
pageContent: 'tigris is a cloud-native vector db',
metadata: { foo: 'bar' }
}
]
*/

此页面对您有帮助吗?


您也可以在 GitHub 上留下详细的反馈 GitHub.