Milvus
Milvus 是一个为嵌入相似性搜索和 AI 应用构建的向量数据库。
¥Milvus is a vector database built for embeddings similarity search and AI applications.
Compatibility
仅在 Node.js 上可用。
¥Only available on Node.js.
设置
¥Setup
在你的计算机上使用 Docker 运行 Milvus 实例 docs
¥Run Milvus instance with Docker on your computer docs
安装 Milvus Node.js SDK。
¥Install the Milvus Node.js SDK.
- npm
- Yarn
- pnpm
npm install -S @zilliz/milvus2-sdk-node
yarn add @zilliz/milvus2-sdk-node
pnpm add @zilliz/milvus2-sdk-node
运行代码前,请为 Milvus 设置环境变量
¥Setup Env variables for Milvus before running the code
3.1 OpenAI
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE
export MILVUS_URL=YOUR_MILVUS_URL_HERE # for example http://localhost:195303.2 Azure OpenAI
export AZURE_OPENAI_API_KEY=YOUR_AZURE_OPENAI_API_KEY_HERE
export AZURE_OPENAI_API_INSTANCE_NAME=YOUR_AZURE_OPENAI_INSTANCE_NAME_HERE
export AZURE_OPENAI_API_DEPLOYMENT_NAME=YOUR_AZURE_OPENAI_DEPLOYMENT_NAME_HERE
export AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME=YOUR_AZURE_OPENAI_COMPLETIONS_DEPLOYMENT_NAME_HERE
export AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=YOUR_AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME_HERE
export AZURE_OPENAI_API_VERSION=YOUR_AZURE_OPENAI_API_VERSION_HERE
export AZURE_OPENAI_BASE_PATH=YOUR_AZURE_OPENAI_BASE_PATH_HERE
export MILVUS_URL=YOUR_MILVUS_URL_HERE # for example http://localhost:19530
索引和查询文档
¥Index and query docs
tip
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/core
yarn add @langchain/openai @langchain/core
pnpm add @langchain/openai @langchain/core
import { Milvus } from "langchain/vectorstores/milvus";
import { OpenAIEmbeddings } from "@langchain/openai";
// text sample from Godel, Escher, Bach
const vectorStore = await Milvus.fromTexts(
[
"Tortoise: Labyrinth? Labyrinth? Could it Are we in the notorious Little\
Harmonic Labyrinth of the dreaded Majotaur?",
"Achilles: Yiikes! What is that?",
"Tortoise: They say-although I person never believed it myself-that an I\
Majotaur has created a tiny labyrinth sits in a pit in the middle of\
it, waiting innocent victims to get lost in its fears complexity.\
Then, when they wander and dazed into the center, he laughs and\
laughs at them-so hard, that he laughs them to death!",
"Achilles: Oh, no!",
"Tortoise: But it's only a myth. Courage, Achilles.",
],
[{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }],
new OpenAIEmbeddings(),
{
collectionName: "goldel_escher_bach",
}
);
// or alternatively from docs
const vectorStore = await Milvus.fromDocuments(docs, new OpenAIEmbeddings(), {
collectionName: "goldel_escher_bach",
});
const response = await vectorStore.similaritySearch("scared", 2);
从现有集合中查询文档
¥Query docs from existing collection
import { Milvus } from "langchain/vectorstores/milvus";
import { OpenAIEmbeddings } from "@langchain/openai";
const vectorStore = await Milvus.fromExistingCollection(
new OpenAIEmbeddings(),
{
collectionName: "goldel_escher_bach",
}
);
const response = await vectorStore.similaritySearch("scared", 2);
相关
¥Related
向量存储 概念指南
¥Vector store conceptual guide
向量存储 操作指南
¥Vector store how-to guides