Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-to-lemonade-hq #1

Open
wants to merge 3 commits into
base: opensearch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
nodeLinker: node-modules

npmRegistryServer: "https://npm.pkg.github.com/lemonade-hq"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
Expand Down
103 changes: 103 additions & 0 deletions docs/docs/modules/indexes/vector_stores/integrations/opensearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# OpenSearch

Langchain.js accepts [@opensearch-project/opensearch](https://opensearch.org/docs/latest/clients/javascript/index/)
as the client for OpenSearch vectorstore. Install the client with

```bash npm2yarn
npm install -S dotenv langchain @opensearch-project/opensearch
```

## Index docs

```typescript
import { Client } from "@opensearch-project/opensearch";
import * as dotenv from "dotenv";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { OpenSearchVectorStore } from "langchain/vectorstores";

dotenv.config();

const client = new Client({
nodes: [process.env.OPENSEARCH_URL ?? "http://127.0.0.1:9200"],
});

const docs = [
new Document({
metadata: { foo: "bar" },
pageContent: "opensearch is also a vector db",
}),
new Document({
metadata: { foo: "bar" },
pageContent: "the quick brown fox jumped over the lazy dog",
}),
new Document({
metadata: { baz: "qux" },
pageContent: "lorem ipsum dolor sit amet",
}),
new Document({
metadata: { baz: "qux" },
pageContent: "OpenSearch is a scalable, flexible, and extensible open-source software suite for search, analytics, and observability applications",
}),
];

await OpenSearchVectorStore.fromDocuments(docs, new OpenAIEmbeddings(), {
client,
indexName: process.env.OPENSEARCH_INDEX, // Will default to `documents`
});
```

## Query docs

```typescript
import { Client } from "@opensearch-project/opensearch";
import * as dotenv from "dotenv";
import { VectorDBQAChain } from "langchain/chains";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { OpenAI } from "langchain/llms";
import { OpenSearchVectorStore } from "langchain/vectorstores";

dotenv.config();

const client = new Client({
nodes: [process.env.OPENSEARCH_URL ?? "http://127.0.0.1:9200"],
});

const vectorStore = new OpenSearchVectorStore(new OpenAIEmbeddings(), {
client,
});

/* Search the vector DB independently with meta filters */
const results = await vectorStore.similaritySearch("hello world", 1);
console.log(JSON.stringify(results, null, 2));
/* [
{
"pageContent": "Hello world",
"metadata": {
"id": 2
}
}
] */

/* Use as part of a chain (currently no metadata filters) */
const model = new OpenAI();
const chain = VectorDBQAChain.fromLLM(model, vectorStore, {
k: 1,
returnSourceDocuments: true,
});
const response = await chain.call({ query: "What is opensearch?" });
console.log(JSON.stringify(response, null, 2));
/*
{
"text": " Opensearch is a collection of technologies that allow search engines to publish search results in a standard format, making it easier for users to search across multiple sites.",
"sourceDocuments": [
{
"pageContent": "What's this?",
"metadata": {
"id": 3
}
}
]
}
*/
```
1 change: 1 addition & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ANTHROPIC_API_KEY=ADD_YOURS_HERE
COHERE_API_KEY=ADD_YOURS_HERE
HUGGINGFACEHUB_API_KEY=ADD_YOURS_HERE
OPENAI_API_KEY=ADD_YOURS_HERE
OPENSEARCH_URL=http://127.0.0.1:9200
PINECONE_API_KEY=ADD_YOURS_HERE
PINECONE_ENVIRONMENT=ADD_YOURS_HERE
PINECONE_INDEX=ADD_YOURS_HERE
Expand Down
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dependencies": {
"@dqbd/tiktoken": "^1.0.2",
"@getmetal/metal-sdk": "^1.0.12",
"@opensearch-project/opensearch": "^2.2.0",
"@pinecone-database/pinecone": "^0.0.10",
"@prisma/client": "^4.11.0",
"@supabase/supabase-js": "^2.10.0",
Expand Down
42 changes: 42 additions & 0 deletions examples/src/indexes/vector_stores/opensearch/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Reference:
# https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#sample-docker-composeyml
version: '3'
services:
opensearch:
image: opensearchproject/opensearch:2.6.0
container_name: opensearch
environment:
- cluster.name=opensearch
- node.name=opensearch
- discovery.type=single-node
- bootstrap.memory_lock=true
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
- "DISABLE_INSTALL_DEMO_CONFIG=true"
- "DISABLE_SECURITY_PLUGIN=true"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- opensearch_data:/usr/share/opensearch/data
ports:
- 9200:9200
- 9600:9600
networks:
- opensearch
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:latest # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes
container_name: opensearch-dashboards
ports:
- 5601:5601 # Map host port 5601 to container port 5601
expose:
- "5601" # Expose port 5601 for web access to OpenSearch Dashboards
environment:
OPENSEARCH_HOSTS: '["http://opensearch:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query
DISABLE_SECURITY_DASHBOARDS_PLUGIN: "true" # disables security dashboards plugin in OpenSearch Dashboards
networks:
- opensearch
networks:
opensearch:
volumes:
opensearch_data:
24 changes: 24 additions & 0 deletions examples/src/indexes/vector_stores/opensearch/opensearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Run with: yarn example src/indexes/vector_stores/opensearch/opensearch.ts

import { Client } from "@opensearch-project/opensearch";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { OpenSearchVectorStore } from "langchain/vectorstores";

export async function run() {
const client = new Client({
nodes: [process.env.OPENSEARCH_URL ?? "http://127.0.0.1:9200"],
});

const vectorStore = await OpenSearchVectorStore.fromTexts(
["Hello world", "Bye bye", "What's this?"],
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings(),
{
client,
indexName: "documents",
}
);

const resultOne = await vectorStore.similaritySearch("Hello world", 1);
console.log(resultOne);
}
1 change: 1 addition & 0 deletions langchain/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ANTHROPIC_API_KEY=ADD_YOURS_HERE
COHERE_API_KEY=ADD_YOURS_HERE
HUGGINGFACEHUB_API_KEY=ADD_YOURS_HERE
OPENAI_API_KEY=ADD_YOURS_HERE
OPENSEARCH_URL=http://127.0.0.1:9200
PINECONE_API_KEY=ADD_YOURS_HERE
PINECONE_ENVIRONMENT=ADD_YOURS_HERE
PINECONE_INDEX=ADD_YOURS_HERE
Expand Down
9 changes: 6 additions & 3 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
],
"repository": {
"type": "git",
"url": "[email protected]:hwchase17/langchainjs.git"
"url": "[email protected]:lemonade-hq/langchainjs.git"
},
"scripts": {
"build": "yarn clean && yarn build:esm && yarn build:cjs && node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js",
Expand Down Expand Up @@ -106,6 +106,7 @@
"@getmetal/metal-sdk": "^1.0.12",
"@huggingface/inference": "^1.5.1",
"@jest/globals": "^29.5.0",
"@opensearch-project/opensearch": "^2.2.0",
"@pinecone-database/pinecone": "^0.0.10",
"@supabase/supabase-js": "^2.10.0",
"@tsconfig/recommended": "^1.0.2",
Expand Down Expand Up @@ -153,6 +154,7 @@
"@dqbd/tiktoken": "^1.0.2",
"@getmetal/metal-sdk": "*",
"@huggingface/inference": "^1.5.1",
"@opensearch-project/opensearch": "*",
"@pinecone-database/pinecone": "^0.0.10",
"@supabase/supabase-js": "^2.10.0",
"cheerio": "^1.0.0-rc.12",
Expand Down Expand Up @@ -246,7 +248,8 @@
"zod": "^3.21.4"
},
"publishConfig": {
"access": "public"
"access": "public",
"registry": "https://npm.pkg.github.com/lemonade-hq"
},
"keywords": [
"llm",
Expand Down Expand Up @@ -370,4 +373,4 @@
},
"./package.json": "./package.json"
}
}
}
1 change: 1 addition & 0 deletions langchain/src/vectorstores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { PineconeStore } from "./pinecone.js";
export { VectorStore, SaveableVectorStore } from "./base.js";
export { SupabaseVectorStore } from "./supabase.js";
export { PrismaVectorStore } from "./prisma.js";
export { OpenSearchVectorStore } from "./opensearch.js";
Loading