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(opensearch): implement filtering by metadata attributes + integr…
…ation test
- Loading branch information
1 parent
fa8006b
commit 37f1b8f
Showing
5 changed files
with
104 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ | |
"tsx": "^3.12.3", | ||
"typescript": "^4.9.5" | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -803,4 +803,4 @@ | |
}, | ||
"./package.json": "./package.json" | ||
} | ||
} | ||
} |
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,42 @@ | ||
/* eslint-disable no-process-env */ | ||
import { test, expect } from "@jest/globals"; | ||
import { Client } from "@opensearch-project/opensearch"; | ||
import { OpenAIEmbeddings } from "../../embeddings/index.js"; | ||
import { OpenSearchVectorStore } from "../opensearch.js"; | ||
import { Document } from "../../document.js"; | ||
|
||
test("OpenSearchVectorStore integration", async () => { | ||
const client = new Client({ | ||
nodes: [process.env.OPENSEARCH_URL!], | ||
}); | ||
|
||
const indexName = "test_index"; | ||
|
||
const embeddings = new OpenAIEmbeddings(undefined, { | ||
baseOptions: { temperature: 0 }, | ||
}); | ||
const store = new OpenSearchVectorStore(embeddings, { client, indexName }); | ||
await store.deleteIfExists(); | ||
|
||
expect(store).toBeDefined(); | ||
|
||
await store.addDocuments([ | ||
{ pageContent: "hello", metadata: { a: 2 } }, | ||
{ pageContent: "car", metadata: { a: 1 } }, | ||
{ pageContent: "adjective", metadata: { a: 1 } }, | ||
{ pageContent: "hi", metadata: { a: 1 } }, | ||
]); | ||
|
||
const results1 = await store.similaritySearch("hello!", 1); | ||
|
||
expect(results1).toHaveLength(1); | ||
expect(results1).toEqual([ | ||
new Document({ metadata: { a: 2 }, pageContent: "hello" }), | ||
]); | ||
|
||
const results2 = await store.similaritySearchWithScore("hello!", 1, { | ||
a: 1, | ||
}); | ||
|
||
expect(results2).toHaveLength(1); | ||
}); |
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