Skip to content

Commit

Permalink
Move /retrievers to granular endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Apr 9, 2023
1 parent 1340ceb commit b156d8c
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/src/chains/retrieval_qa_with_remote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAI } from "langchain/llms/openai";
import { RetrievalQAChain } from "langchain/chains";
import { RemoteLangChainRetriever } from "langchain/retrievers";
import { RemoteLangChainRetriever } from "langchain/retrievers/remote";

export const run = async () => {
// Initialize the LLM to use to answer the question.
Expand Down
2 changes: 1 addition & 1 deletion examples/src/retrievers/chatgpt-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatGPTPluginRetriever } from "langchain/retrievers";
import { ChatGPTPluginRetriever } from "langchain/retrievers/remote";

export const run = async () => {
const retriever = new ChatGPTPluginRetriever({
Expand Down
2 changes: 1 addition & 1 deletion examples/src/retrievers/metal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import Metal from "@getmetal/metal-sdk";
import { MetalRetriever } from "langchain/retrievers";
import { MetalRetriever } from "langchain/retrievers/metal";

export const run = async () => {
const MetalSDK = Metal.default;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/retrievers/supabase_hybrid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { createClient } from "@supabase/supabase-js";
import { SupabaseHybridSearch } from "langchain/retrievers";
import { SupabaseHybridSearch } from "langchain/retrievers/supabase";

export const run = async () => {
const client = createClient(
Expand Down
9 changes: 9 additions & 0 deletions langchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ output_parsers.d.ts
retrievers.cjs
retrievers.js
retrievers.d.ts
retrievers/remote.cjs
retrievers/remote.js
retrievers/remote.d.ts
retrievers/supabase.cjs
retrievers/supabase.js
retrievers/supabase.d.ts
retrievers/metal.cjs
retrievers/metal.js
retrievers/metal.d.ts
cache.cjs
cache.js
cache.d.ts
Expand Down
32 changes: 29 additions & 3 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
"retrievers.cjs",
"retrievers.js",
"retrievers.d.ts",
"retrievers/remote.cjs",
"retrievers/remote.js",
"retrievers/remote.d.ts",
"retrievers/supabase.cjs",
"retrievers/supabase.js",
"retrievers/supabase.d.ts",
"retrievers/metal.cjs",
"retrievers/metal.js",
"retrievers/metal.d.ts",
"cache.cjs",
"cache.js",
"cache.d.ts",
Expand Down Expand Up @@ -544,9 +553,26 @@
"require": "./output_parsers.cjs"
},
"./retrievers": {
"types": "./retrievers.d.ts",
"import": "./retrievers.js",
"require": "./retrievers.cjs"
"node": {
"types": "./retrievers.d.ts",
"import": "./retrievers.js",
"require": "./retrievers.cjs"
}
},
"./retrievers/remote": {
"types": "./retrievers/remote.d.ts",
"import": "./retrievers/remote.js",
"require": "./retrievers/remote.cjs"
},
"./retrievers/supabase": {
"types": "./retrievers/supabase.d.ts",
"import": "./retrievers/supabase.js",
"require": "./retrievers/supabase.cjs"
},
"./retrievers/metal": {
"types": "./retrievers/metal.d.ts",
"import": "./retrievers/metal.js",
"require": "./retrievers/metal.cjs"
},
"./cache": {
"types": "./cache.d.ts",
Expand Down
1 change: 1 addition & 0 deletions langchain/retrievers/base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../dist/retrievers/base.cjs');
1 change: 1 addition & 0 deletions langchain/retrievers/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../dist/retrievers/base.js'
1 change: 1 addition & 0 deletions langchain/retrievers/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../dist/retrievers/base.js'
6 changes: 6 additions & 0 deletions langchain/scripts/create-entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const entrypoints = {
output_parsers: "output_parsers/index",
// retrievers
retrievers: "retrievers/index",
"retrievers/remote": "retrievers/remote/index",
"retrievers/supabase": "retrievers/supabase",
"retrievers/metal": "retrievers/metal",
// cache
cache: "cache",
};
Expand All @@ -79,6 +82,7 @@ const deprecatedNodeOnly = [
"llms",
"chat_models",
"vectorstores",
"retrievers",
];

// Entrypoints in this list require an optional dependency to be installed.
Expand All @@ -97,6 +101,8 @@ const requiresOptionalDependency = [
"vectorstores/pinecone",
"vectorstores/supabase",
"sql_db",
"retrievers/supabase",
"retrievers/metal",
];

// List of test-exports-* packages which we use to test that the exports field
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/retrievers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export { ChatGPTPluginRetriever } from "./remote/chatgpt-plugin.js";
export {
SupabaseHybridSearch,
SupabaseHybridSearchParams,
} from "./supabase-hybrid-search.js";
} from "./supabase.js";
export { RemoteLangChainRetriever } from "./remote/remote-retriever.js";
export { MetalRetriever } from "./metal.js";
6 changes: 2 additions & 4 deletions langchain/src/retrievers/metal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type MetalSDK from "@getmetal/metal-sdk";

import { BaseRetriever } from "../schema/index.js";
import { Document } from "../document.js";

export interface MetalRetrieverFields {
client: MetalSDK.default;
client: import("@getmetal/metal-sdk").default;
}

interface ResponseItem {
Expand All @@ -13,7 +11,7 @@ interface ResponseItem {
}

export class MetalRetriever extends BaseRetriever {
client: MetalSDK.default;
private client: import("@getmetal/metal-sdk").default;

constructor(fields: MetalRetrieverFields) {
super();
Expand Down
3 changes: 3 additions & 0 deletions langchain/src/retrievers/remote/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { RemoteRetriever } from "./base.js";
export { ChatGPTPluginRetriever } from "./chatgpt-plugin.js";
export { RemoteLangChainRetriever } from "./remote-retriever.js";
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { test, expect } from "@jest/globals";
import { createClient } from "@supabase/supabase-js";
import { OpenAIEmbeddings } from "../../embeddings/index.js";
import { SupabaseHybridSearch } from "../supabase-hybrid-search.js";
import { SupabaseHybridSearch } from "../supabase.js";

test("Supabase hybrid keyword search", async () => {
const client = createClient(
Expand Down
4 changes: 3 additions & 1 deletion langchain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
"src/sql_db.ts",
"src/callbacks/index.ts",
"src/output_parsers/index.ts",
"src/retrievers/index.ts",
"src/retrievers/remote/index.ts",
"src/retrievers/supabase.ts",
"src/retrievers/metal.ts",
"src/cache.ts"
],
"excludePrivate": true,
Expand Down
2 changes: 1 addition & 1 deletion test-exports-cf/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export * from "langchain/chat_models/anthropic";
export * from "langchain/schema";
export * from "langchain/callbacks";
export * from "langchain/output_parsers";
export * from "langchain/retrievers";
export * from "langchain/retrievers/remote";
export * from "langchain/cache";
2 changes: 1 addition & 1 deletion test-exports-cjs/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ const chat_models_anthropic = require("langchain/chat_models/anthropic");
const schema = require("langchain/schema");
const callbacks = require("langchain/callbacks");
const output_parsers = require("langchain/output_parsers");
const retrievers = require("langchain/retrievers");
const retrievers_remote = require("langchain/retrievers/remote");
const cache = require("langchain/cache");
2 changes: 1 addition & 1 deletion test-exports-cra/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export * from "langchain/chat_models/anthropic";
export * from "langchain/schema";
export * from "langchain/callbacks";
export * from "langchain/output_parsers";
export * from "langchain/retrievers";
export * from "langchain/retrievers/remote";
export * from "langchain/cache";
2 changes: 1 addition & 1 deletion test-exports-esm/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import * as chat_models_anthropic from "langchain/chat_models/anthropic";
import * as schema from "langchain/schema";
import * as callbacks from "langchain/callbacks";
import * as output_parsers from "langchain/output_parsers";
import * as retrievers from "langchain/retrievers";
import * as retrievers_remote from "langchain/retrievers/remote";
import * as cache from "langchain/cache";

0 comments on commit b156d8c

Please sign in to comment.