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 MyScale as vectorStore provider (#1)
feat: add MyScale as vectorStore provider
- Loading branch information
Showing
12 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
docs/docs/modules/indexes/vector_stores/integrations/myscale.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,76 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
# MyScale | ||
|
||
[MyScale](https://myscale.com/) is an emerging AI database that harmonizes the power of vector search and SQL analytics, providing a managed, efficient, and responsive experience. | ||
|
||
:::tip Compatibility | ||
Only available on Node.js. | ||
::: | ||
|
||
## Setup | ||
|
||
1. Launch a cluster through [MyScale's Web Console](https://console.myscale.com/), see [the MyScale documentation](https://docs.myscale.com/en/quickstart/) for more information. | ||
2. Install the Node.js SDK. | ||
|
||
```bash npm2yarn | ||
npm install -S @clickhouse/client | ||
``` | ||
|
||
## Index and query docs | ||
|
||
```typescript | ||
import { MyScaleStore } from "langchain/vectorstores/myscale"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
const vectorStore = await MyScaleStore.fromTexts( | ||
["Hello world", "Bye bye", "hello nice world"], | ||
[ | ||
{ id: 2, name: "2" }, | ||
{ id: 1, name: "1" }, | ||
{ id: 3, name: "3" }, | ||
], | ||
new OpenAIEmbeddings(), | ||
{ | ||
host: process.env.MYSCALE_HOST || "https://localhost:8443", | ||
username: process.env.MYSCALE_USERNAME || "username", | ||
password: process.env.MYSCALE_PASSWORD || "password", | ||
} | ||
); | ||
|
||
const results = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(results); | ||
|
||
const filteredResults = await vectorStore.similaritySearch("hello world", 1, { | ||
whereStr: "metadata.name = '1'", | ||
}); | ||
console.log(filteredResults); | ||
``` | ||
|
||
## Query docs from existing collection | ||
|
||
```typescript | ||
import { MyScaleStore } from "langchain/vectorstores/myscale"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
const vectorStore = await MyScaleStore.fromExistingIndex( | ||
new OpenAIEmbeddings(), | ||
{ | ||
host: process.env.MYSCALE_HOST || "https://localhost:8443", | ||
username: process.env.MYSCALE_USERNAME || "username", | ||
password: process.env.MYSCALE_PASSWORD || "password", | ||
database: "your_database", // default is default | ||
table: "your_table", // default is vector_table | ||
} | ||
); | ||
|
||
const results = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(results); | ||
|
||
const filteredResults = await vectorStore.similaritySearch("hello world", 1, { | ||
whereStr: "metadata.name = '1'", | ||
}); | ||
console.log(filteredResults); | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MyScaleStore } from "langchain/vectorstores/myscale"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
export async function run() { | ||
// Create a store and fill it with some texts + metadata | ||
const vectorStore = await MyScaleStore.fromTexts( | ||
["Hello world", "Bye bye", "hello nice world"], | ||
[ | ||
{ id: 2, name: "2" }, | ||
{ id: 1, name: "1" }, | ||
{ id: 3, name: "3" }, | ||
], | ||
new OpenAIEmbeddings(), | ||
{ | ||
host: process.env.MYSCALE_HOST || "https://localhost:8443", | ||
username: process.env.MYSCALE_USERNAME || "username", | ||
password: process.env.MYSCALE_PASSWORD || "password", | ||
} | ||
); | ||
|
||
const results = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(results); | ||
|
||
const filteredResults = await vectorStore.similaritySearch("hello world", 1, { | ||
whereStr: "metadata.name = '1'", | ||
}); | ||
console.log(filteredResults); | ||
} |
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.