forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Milvus as vectorStore provider (langchain-ai#600)
* feat: add Milvus as vectorStore provider * docs: add docs for Milvus * fix: add Milvus's missing method "fromExistingCollection" * feat: add example * metadata supports complex data. * Add entrypoint, lint, fix some issues * Update yarnlock * Fix CI --------- Co-authored-by: Nuno Campos <[email protected]>
- Loading branch information
1 parent
f37a880
commit 883ddec
Showing
13 changed files
with
883 additions
and
2 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
docs/docs/modules/indexes/vector_stores/integrations/milvus.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
# Milvus | ||
|
||
[Milvus](https://milvus.io/) is an vector database built for embedding similarity search and AI applications. | ||
|
||
:::tip Compatibility | ||
Only available on Node.js. | ||
::: | ||
|
||
## Setup | ||
|
||
1. Run milvus instance inside of docker on your computer [docs](https://milvus.io/docs/v2.1.x/install_standalone-docker.md) | ||
2. Install the Milvus Node.js SDK. | ||
|
||
```bash npm2yarn | ||
npm install -S @zilliz/milvus2-sdk-node | ||
``` | ||
|
||
3. Setup Env variables for Milvus before running the code | ||
|
||
```bash | ||
export OPENAI_API_KEY=YOUR_OPEN_API_HERE | ||
export MILVUS_URL=YOUR_MILVUS_URL_HERE # for example http://localhost:19530 | ||
``` | ||
|
||
## Index and query docs | ||
|
||
```typescript | ||
import { Milvus } from "langchain/vectorstores/milvus"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/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 | ||
|
||
```typescript | ||
import { Milvus } from "langchain/vectorstores/milvus"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
const vectorStore = await Milvus.fromExistingCollection( | ||
new OpenAIEmbeddings(), | ||
{ | ||
collectionName: "goldel-escher-bach", | ||
} | ||
); | ||
|
||
const response = await vectorStore.similaritySearch("scared", 2); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Milvus } from "langchain/vectorstores/milvus"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
export const run = async () => { | ||
const vectorStore = await Milvus.fromTexts( | ||
["Hello world", "Bye bye", "hello nice world"], | ||
[{ id: 2 }, { id: 1 }, { id: 3 }], | ||
new OpenAIEmbeddings() | ||
); | ||
|
||
const resultOne = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(resultOne); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.