SingleStore
SingleStoreDB是一款高性能,分布式数据库系统。长期以来,它一直支持dot_product等向量函数,从而成为需要文本相似度匹配的AI应用程序的最佳解决方案。
兼容性
仅Node.js可用。
LangChain.js接受mysql2/promise Pool
作为SingleStore向量存储的连接池。
设置
- npm
- Yarn
- pnpm
npm install -S mysql2
yarn add mysql2
pnpm add mysql2
用法
import { SingleStoreVectorStore } from "langchain/vectorstores/singlestore";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { createPool } from "mysql2/promise";
export const run = async () => {
const pool = createPool({
host: process.env.SINGLESTORE_HOST,
port: Number(process.env.SINGLESTORE_PORT),
user: process.env.SINGLESTORE_USERNAME,
password: process.env.SINGLESTORE_PASSWORD,
database: process.env.SINGLESTORE_DATABASE,
});
const vectorStore = await SingleStoreVectorStore.fromTexts(
["Hello world", "Bye bye", "hello nice world"],
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings(),
{
connectionPool: pool,
}
);
const resultOne = await vectorStore.similaritySearch("hello world", 1);
console.log(resultOne);
await pool.end();
};