Skip to main content

Tigris

Tigris使向量嵌入的构建人工智能应用程序变得轻松。 它是一个完全托管的云原生数据库,允许您存储和索引文档和向量嵌入,以进行快速和可扩展的向量搜索。

兼容性

仅在Node.js上可用。

安装

1. 安装Tigris SDK

按以下方式安装SDK


npm install -S @tigrisdata/vector

2. 获取Tigris API凭据

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

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

索引文档

import { VectorDocumentStore } from "@tigrisdata/vector";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "langchain/embeddings/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/embeddings/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' }
}
]
*/