Tigris
Tigris 使得使用向量嵌入构建 AI 应用程序变得容易。它是一个完全托管的云原生数据库,允许您存储和索引文档和向量嵌入,以便进行快速且可扩展的向量搜索。
兼容性
仅在 Node.js 上可用。
设置
1. 安装 Tigris SDK
按如下方式安装 SDK
- npm
- Yarn
- pnpm
npm install -S @tigrisdata/vector
yarn add @tigrisdata/vector
pnpm add @tigrisdata/vector
2. 获取 Tigris API 凭据
您可以在 此处 注册免费的 Tigris 帐户。
注册 Tigris 帐户后,创建一个名为 vectordemo
的新项目。接下来,记下 clientId
和 clientSecret
,您可以在项目的“应用程序密钥”部分获取它们。
索引文档
提示
- npm
- Yarn
- pnpm
npm install -S @langchain/openai
yarn add @langchain/openai
pnpm add @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' }
}
]
*/