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.
Implement ClickHouse Support (langchain-ai#3342)
* Implement ClickHouse Support Co-Authored-By: CalebZhang <[email protected]> Co-Authored-By: Divyansh Kachchhava <[email protected]> Co-Authored-By: Alfred Tze-Hong Ha <[email protected]> * Update ClickHouse client dependency Co-Authored-By: Divyansh Kachchhava <[email protected]> Co-Authored-By: CalebZhang <[email protected]> Co-Authored-By: Alfred Tze-Hong Ha <[email protected]> * Update int test to use test.skip() * Fix SQL injection risk * Add peer deps docs * fix yarn lint issue --------- Co-authored-by: CalebZhang <[email protected]> Co-authored-by: Divyansh Kachchhava <[email protected]> Co-authored-by: Alfred Tze-Hong Ha <[email protected]> Co-authored-by: jacoblee93 <[email protected]> Co-authored-by: CalebZhang <[email protected]>
- Loading branch information
1 parent
8684351
commit 85470e4
Showing
16 changed files
with
583 additions
and
19 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
docs/core_docs/docs/integrations/vectorstores/clickhouse.mdx
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,37 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# ClickHouse | ||
|
||
:::tip Compatibility | ||
Only available on Node.js. | ||
::: | ||
|
||
[ClickHouse](https://clickhouse.com/) is a robust and open-source columnar database that is used for handling analytical queries and efficient storage, ClickHouse is designed to provide a powerful combination of vector search and analytics. | ||
|
||
## Setup | ||
|
||
1. Launch a ClickHouse cluster. Refer to the [ClickHouse Installation Guide](https://clickhouse.com/docs/en/getting-started/install/) for details. | ||
2. After launching a ClickHouse cluster, retrieve the `Connection Details` from the cluster's `Actions` menu. You will need the host, port, username, and password. | ||
3. Install the required Node.js peer dependency for ClickHouse in your workspace. | ||
|
||
You will need to install the following peer dependencies: | ||
|
||
```bash npm2yarn | ||
npm install -S @clickhouse/client mysql2 | ||
``` | ||
|
||
## Index and Query Docs | ||
|
||
import InsertExample from "@examples/indexes/vector_stores/clickhouse_fromTexts.ts"; | ||
|
||
<CodeBlock language="typescript">{InsertExample}</CodeBlock> | ||
|
||
## Query Docs From an Existing Collection | ||
|
||
import SearchExample from "@examples/indexes/vector_stores/clickhouse_search.ts"; | ||
|
||
<CodeBlock language="typescript">{SearchExample}</CodeBlock> |
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
35 changes: 35 additions & 0 deletions
35
examples/src/indexes/vector_stores/clickhouse_fromTexts.ts
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,35 @@ | ||
import { ClickHouseStore } from "langchain/vectorstores/clickhouse"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
// Initialize ClickHouse store from texts | ||
const vectorStore = await ClickHouseStore.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.CLICKHOUSE_HOST || "localhost", | ||
port: process.env.CLICKHOUSE_PORT || 8443, | ||
username: process.env.CLICKHOUSE_USER || "username", | ||
password: process.env.CLICKHOUSE_PASSWORD || "password", | ||
database: process.env.CLICKHOUSE_DATABASE || "default", | ||
table: process.env.CLICKHOUSE_TABLE || "vector_table", | ||
} | ||
); | ||
|
||
// Sleep 1 second to ensure that the search occurs after the successful insertion of data. | ||
// eslint-disable-next-line no-promise-executor-return | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
// Perform similarity search without filtering | ||
const results = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(results); | ||
|
||
// Perform similarity search with filtering | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ClickHouseStore } from "langchain/vectorstores/clickhouse"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
// Initialize ClickHouse store | ||
const vectorStore = await ClickHouseStore.fromExistingIndex( | ||
new OpenAIEmbeddings(), | ||
{ | ||
host: process.env.CLICKHOUSE_HOST || "localhost", | ||
port: process.env.CLICKHOUSE_PORT || 8443, | ||
username: process.env.CLICKHOUSE_USER || "username", | ||
password: process.env.CLICKHOUSE_PASSWORD || "password", | ||
database: process.env.CLICKHOUSE_DATABASE || "default", | ||
table: process.env.CLICKHOUSE_TABLE || "vector_table", | ||
} | ||
); | ||
|
||
// Sleep 1 second to ensure that the search occurs after the successful insertion of data. | ||
// eslint-disable-next-line no-promise-executor-return | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
// Perform similarity search without filtering | ||
const results = await vectorStore.similaritySearch("hello world", 1); | ||
console.log(results); | ||
|
||
// Perform similarity search with filtering | ||
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
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.