From ed8405f1a4382545295c93fdde317c099db30eb1 Mon Sep 17 00:00:00 2001 From: erhant Date: Mon, 16 Dec 2024 10:59:10 +0300 Subject: [PATCH] remove dria --- .../docs/integrations/retrievers/dria.mdx | 44 ------- examples/src/retrievers/dria.ts | 14 -- libs/langchain-community/.gitignore | 4 - libs/langchain-community/langchain.config.js | 2 - libs/langchain-community/package.json | 18 --- .../src/load/import_constants.ts | 1 - .../src/load/import_type.ts | 1 - .../src/retrievers/dria.ts | 122 ------------------ .../src/retrievers/tests/dria.int.test.ts | 16 --- yarn.lock | 14 -- 10 files changed, 236 deletions(-) delete mode 100644 docs/core_docs/docs/integrations/retrievers/dria.mdx delete mode 100644 examples/src/retrievers/dria.ts delete mode 100644 libs/langchain-community/src/retrievers/dria.ts delete mode 100644 libs/langchain-community/src/retrievers/tests/dria.int.test.ts diff --git a/docs/core_docs/docs/integrations/retrievers/dria.mdx b/docs/core_docs/docs/integrations/retrievers/dria.mdx deleted file mode 100644 index 5a29ebc004eb..000000000000 --- a/docs/core_docs/docs/integrations/retrievers/dria.mdx +++ /dev/null @@ -1,44 +0,0 @@ ---- -hide_table_of_contents: true ---- - -# Dria Retriever - -The [Dria](https://dria.co/profile) retriever allows an agent to perform a text-based search across a comprehensive knowledge hub. - -## Setup - -To use Dria retriever, first install Dria JS client: - -```bash npm2yarn -npm install dria -``` - -You need to provide two things to the retriever: - -- **API Key**: you can get yours at your [profile page](https://dria.co/profile) when you create an account. -- **Contract ID**: accessible at the top of the page when viewing a knowledge or in its URL. - For example, the Bitcoin whitepaper is uploaded on Dria at https://dria.co/knowledge/2KxNbEb040GKQ1DSDNDsA-Fsj_BlQIEAlzBNuiapBR0, so its contract ID is `2KxNbEb040GKQ1DSDNDsA-Fsj_BlQIEAlzBNuiapBR0`. - Contract ID can be omitted during instantiation, and later be set via `dria.contractId = "your-contract"` - -Dria retriever exposes the underlying [Dria client](https://npmjs.com/package/dria) as well, refer to the [Dria documentation](https://github.com/firstbatchxyz/dria-js-client?tab=readme-ov-file#usage) to learn more about the client. - -## Usage - -import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; - - - -```bash npm2yarn -npm install dria @langchain/community @langchain/core -``` - -import CodeBlock from "@theme/CodeBlock"; -import Example from "@examples/retrievers/dria.ts"; - -{Example} - -## Related - -- Retriever [conceptual guide](/docs/concepts/retrievers) -- Retriever [how-to guides](/docs/how_to/#retrievers) diff --git a/examples/src/retrievers/dria.ts b/examples/src/retrievers/dria.ts deleted file mode 100644 index 4de8ec115334..000000000000 --- a/examples/src/retrievers/dria.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { DriaRetriever } from "@langchain/community/retrievers/dria"; - -// contract of TypeScript Handbook v4.9 uploaded to Dria -// https://dria.co/knowledge/-B64DjhUtCwBdXSpsRytlRQCu-bie-vSTvTIT8Ap3g0 -const contractId = "-B64DjhUtCwBdXSpsRytlRQCu-bie-vSTvTIT8Ap3g0"; - -const retriever = new DriaRetriever({ - contractId, // a knowledge to connect to - apiKey: "DRIA_API_KEY", // if not provided, will check env for `DRIA_API_KEY` - topK: 15, // optional: default value is 10 -}); - -const docs = await retriever.invoke("What is a union type?"); -console.log(docs); diff --git a/libs/langchain-community/.gitignore b/libs/langchain-community/.gitignore index 4fde6ded00ff..fce3c1d1e287 100644 --- a/libs/langchain-community/.gitignore +++ b/libs/langchain-community/.gitignore @@ -638,10 +638,6 @@ retrievers/databerry.cjs retrievers/databerry.js retrievers/databerry.d.ts retrievers/databerry.d.cts -retrievers/dria.cjs -retrievers/dria.js -retrievers/dria.d.ts -retrievers/dria.d.cts retrievers/metal.cjs retrievers/metal.js retrievers/metal.d.ts diff --git a/libs/langchain-community/langchain.config.js b/libs/langchain-community/langchain.config.js index 62abeef26886..b044d9f49de5 100644 --- a/libs/langchain-community/langchain.config.js +++ b/libs/langchain-community/langchain.config.js @@ -201,7 +201,6 @@ export const config = { "retrievers/bm25": "retrievers/bm25", "retrievers/chaindesk": "retrievers/chaindesk", "retrievers/databerry": "retrievers/databerry", - "retrievers/dria": "retrievers/dria", "retrievers/metal": "retrievers/metal", "retrievers/remote": "retrievers/remote/index", "retrievers/supabase": "retrievers/supabase", @@ -437,7 +436,6 @@ export const config = { "chat_models/zhipuai", "retrievers/amazon_kendra", "retrievers/amazon_knowledge_base", - "retrievers/dria", "retrievers/metal", "retrievers/supabase", "retrievers/vectara_summary", diff --git a/libs/langchain-community/package.json b/libs/langchain-community/package.json index b759b36153af..78349dd7fb8e 100644 --- a/libs/langchain-community/package.json +++ b/libs/langchain-community/package.json @@ -155,7 +155,6 @@ "discord.js": "^14.14.1", "dotenv": "^16.0.3", "dpdm": "^3.12.0", - "dria": "^0.0.3", "duck-duck-scrape": "^2.2.5", "epub2": "^3.0.1", "eslint": "^8.33.0", @@ -298,7 +297,6 @@ "crypto-js": "^4.2.0", "d3-dsv": "^2.0.0", "discord.js": "^14.14.1", - "dria": "^0.0.3", "duck-duck-scrape": "^2.2.5", "epub2": "^3.0.1", "faiss-node": "^0.5.1", @@ -572,9 +570,6 @@ "discord.js": { "optional": true }, - "dria": { - "optional": true - }, "duck-duck-scrape": { "optional": true }, @@ -2152,15 +2147,6 @@ "import": "./retrievers/databerry.js", "require": "./retrievers/databerry.cjs" }, - "./retrievers/dria": { - "types": { - "import": "./retrievers/dria.d.ts", - "require": "./retrievers/dria.d.cts", - "default": "./retrievers/dria.d.ts" - }, - "import": "./retrievers/dria.js", - "require": "./retrievers/dria.cjs" - }, "./retrievers/metal": { "types": { "import": "./retrievers/metal.d.ts", @@ -3786,10 +3772,6 @@ "retrievers/databerry.js", "retrievers/databerry.d.ts", "retrievers/databerry.d.cts", - "retrievers/dria.cjs", - "retrievers/dria.js", - "retrievers/dria.d.ts", - "retrievers/dria.d.cts", "retrievers/metal.cjs", "retrievers/metal.js", "retrievers/metal.d.ts", diff --git a/libs/langchain-community/src/load/import_constants.ts b/libs/langchain-community/src/load/import_constants.ts index 5930f82690db..5ba8a0471767 100644 --- a/libs/langchain-community/src/load/import_constants.ts +++ b/libs/langchain-community/src/load/import_constants.ts @@ -100,7 +100,6 @@ export const optionalImportEntrypoints: string[] = [ "langchain_community/callbacks/handlers/upstash_ratelimit", "langchain_community/retrievers/amazon_kendra", "langchain_community/retrievers/amazon_knowledge_base", - "langchain_community/retrievers/dria", "langchain_community/retrievers/metal", "langchain_community/retrievers/supabase", "langchain_community/retrievers/vectara_summary", diff --git a/libs/langchain-community/src/load/import_type.ts b/libs/langchain-community/src/load/import_type.ts index 61efffe903c7..553b45662709 100644 --- a/libs/langchain-community/src/load/import_type.ts +++ b/libs/langchain-community/src/load/import_type.ts @@ -19,7 +19,6 @@ export interface SecretMap { CLOUDFLARE_API_TOKEN?: string; COHERE_API_KEY?: string; DATABERRY_API_KEY?: string; - DRIA_API_KEY?: string; FIREWORKS_API_KEY?: string; FRIENDLI_TEAM?: string; FRIENDLI_TOKEN?: string; diff --git a/libs/langchain-community/src/retrievers/dria.ts b/libs/langchain-community/src/retrievers/dria.ts deleted file mode 100644 index 60caec99553b..000000000000 --- a/libs/langchain-community/src/retrievers/dria.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { - BaseRetriever, - type BaseRetrieverInput, -} from "@langchain/core/retrievers"; -import { Document } from "@langchain/core/documents"; -import { getEnvironmentVariable } from "@langchain/core/utils/env"; -import type { DriaParams, SearchOptions as DriaSearchOptions } from "dria"; -import { Dria } from "dria"; - -/** - * Configurations for Dria retriever. - * - * - `contractId`: a Dria knowledge's contract ID. - * - `apiKey`: a Dria API key; if omitted, the retriever will check for `DRIA_API_KEY` environment variable. - * - * The retrieval can be configured with the following options: - * - * - `topK`: number of results to return, max 20. (default: 10) - * - `rerank`: re-rank the results from most to least semantically relevant to the given search query. (default: true) - * - `level`: level of detail for the search, must be an integer from 0 to 5 (inclusive). (default: 1) - * - `field`: CSV field name, only relevant for the CSV files. - */ -export interface DriaRetrieverArgs - extends DriaParams, - BaseRetrieverInput, - DriaSearchOptions {} - -/** - * Class for retrieving documents from knowledge uploaded to Dria. - * - * @example - * ```typescript - * // contract of TypeScript Handbook v4.9 uploaded to Dria - * const contractId = "-B64DjhUtCwBdXSpsRytlRQCu-bie-vSTvTIT8Ap3g0"; - * const retriever = new DriaRetriever({ contractId }); - * - * const docs = await retriever.getRelevantDocuments("What is a union type?"); - * console.log(docs); - * ``` - */ -export class DriaRetriever extends BaseRetriever { - static lc_name() { - return "DriaRetriever"; - } - - lc_namespace = ["langchain", "retrievers", "dria"]; - - get lc_secrets() { - return { apiKey: "DRIA_API_KEY" }; - } - - get lc_aliases() { - return { apiKey: "api_key" }; - } - - apiKey: string; - - public driaClient: Dria; - - private searchOptions: DriaSearchOptions; - - constructor(fields: DriaRetrieverArgs) { - super(fields); - - const apiKey = fields.apiKey ?? getEnvironmentVariable("DRIA_API_KEY"); - if (!apiKey) throw new Error("Missing DRIA_API_KEY."); - this.apiKey = apiKey; - - this.searchOptions = { - topK: fields.topK, - field: fields.field, - rerank: fields.rerank, - level: fields.level, - }; - - this.driaClient = new Dria({ - contractId: fields.contractId, - apiKey: this.apiKey, - }); - } - - /** - * Currently connected knowledge on Dria. - * - * Retriever will use this contract ID while retrieving documents, - * and will throw an error if `undefined`. - * - * In the case that this is `undefined`, the user is expected to - * set contract ID manually, such as after creating a new knowledge & inserting - * data there with the Dria client. - */ - get contractId(): string | undefined { - return this.driaClient.contractId; - } - - set contractId(value: string) { - this.driaClient.contractId = value; - } - - /** - * Retrieves documents from Dria with respect to the configured contract ID, based on - * the given query string. - * - * @param query The query string - * @returns A promise that resolves to an array of documents, with page content as text, - * along with `id` and the relevance `score` within the metadata. - */ - async _getRelevantDocuments(query: string): Promise { - const docs = await this.driaClient.search(query, this.searchOptions); - return docs.map( - (d) => - new Document({ - // dria.search returns a string within the metadata as the content - pageContent: d.metadata, - metadata: { - id: d.id, - score: d.score, - }, - }) - ); - } -} diff --git a/libs/langchain-community/src/retrievers/tests/dria.int.test.ts b/libs/langchain-community/src/retrievers/tests/dria.int.test.ts deleted file mode 100644 index 293e2b60799a..000000000000 --- a/libs/langchain-community/src/retrievers/tests/dria.int.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { test, expect } from "@jest/globals"; -import { DriaRetriever } from "../dria.js"; - -test.skip("DriaRetriever", async () => { - // contract of TypeScript Handbook v4.9 uploaded to Dria - // https://dria.co/knowledge/-B64DjhUtCwBdXSpsRytlRQCu-bie-vSTvTIT8Ap3g0 - const contractId = "-B64DjhUtCwBdXSpsRytlRQCu-bie-vSTvTIT8Ap3g0"; - const topK = 10; - - const retriever = new DriaRetriever({ contractId, topK }); - - const docs = await retriever.getRelevantDocuments("What is a union type?"); - expect(docs.length).toBe(topK); - - // console.log(docs[0].pageContent); -}); diff --git a/yarn.lock b/yarn.lock index 8ca08ed7c45d..6e979bbfd99a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11881,7 +11881,6 @@ __metadata: discord.js: ^14.14.1 dotenv: ^16.0.3 dpdm: ^3.12.0 - dria: ^0.0.3 duck-duck-scrape: ^2.2.5 epub2: ^3.0.1 eslint: ^8.33.0 @@ -12031,7 +12030,6 @@ __metadata: crypto-js: ^4.2.0 d3-dsv: ^2.0.0 discord.js: ^14.14.1 - dria: ^0.0.3 duck-duck-scrape: ^2.2.5 epub2: ^3.0.1 faiss-node: ^0.5.1 @@ -12229,8 +12227,6 @@ __metadata: optional: true discord.js: optional: true - dria: - optional: true duck-duck-scrape: optional: true epub2: @@ -25950,16 +25946,6 @@ __metadata: languageName: node linkType: hard -"dria@npm:^0.0.3": - version: 0.0.3 - resolution: "dria@npm:0.0.3" - dependencies: - axios: ^1.6.5 - zod: ^3.22.4 - checksum: 69d66479cb015e87425fba7f1741e4d895b4f43844e6b8897d3e7fe38e579097f2c4673d534141419d15a72866adf4db12acb9b59b42681ef2c4ee2d301b9267 - languageName: node - linkType: hard - "duck-duck-scrape@npm:^2.2.5": version: 2.2.5 resolution: "duck-duck-scrape@npm:2.2.5"