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

redis[major]: Adds new @langchain/redis integration package #4299

Merged
merged 4 commits into from
Feb 6, 2024
Merged
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
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@langchain/mistralai": "workspace:*",
"@langchain/openai": "workspace:*",
"@langchain/pinecone": "workspace:*",
"@langchain/redis": "workspace:*",
"@langchain/weaviate": "workspace:*",
"@langchain/yandex": "workspace:*",
"@opensearch-project/opensearch": "^2.2.0",
Expand Down Expand Up @@ -70,7 +71,7 @@
"pg": "^8.11.0",
"pickleparser": "^0.2.1",
"prisma": "^4.11.0",
"redis": "^4.6.6",
"redis": "^4.6.13",
"sqlite3": "^5.1.4",
"typeorm": "^0.3.12",
"typesense": "^1.5.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/src/indexes/vector_stores/redis/redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from "redis";
import { OpenAIEmbeddings } from "@langchain/openai";
import { RedisVectorStore } from "@langchain/community/vectorstores/redis";
import { RedisVectorStore } from "@langchain/redis";
import { Document } from "@langchain/core/documents";

const client = createClient({
Expand Down
2 changes: 1 addition & 1 deletion examples/src/indexes/vector_stores/redis/redis_delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from "redis";
import { OpenAIEmbeddings } from "@langchain/openai";
import { RedisVectorStore } from "@langchain/community/vectorstores/redis";
import { RedisVectorStore } from "@langchain/redis";
import { Document } from "@langchain/core/documents";

const client = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from "redis";
import { OpenAIEmbeddings } from "@langchain/openai";
import { RedisVectorStore } from "@langchain/community/vectorstores/redis";
import { RedisVectorStore } from "@langchain/redis";
import { Document } from "@langchain/core/documents";

const client = createClient({
Expand Down
2 changes: 1 addition & 1 deletion examples/src/indexes/vector_stores/redis/redis_query.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from "redis";
import { OpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { RetrievalQAChain } from "langchain/chains";
import { RedisVectorStore } from "@langchain/community/vectorstores/redis";
import { RedisVectorStore } from "@langchain/redis";

const client = createClient({
url: process.env.REDIS_URL ?? "redis://localhost:6379",
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/cache/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RedisClientType =
| ReturnType<typeof createCluster>;

/**
* @deprecated Import from "@langchain/community/caches/ioredis" instead.
* @deprecated Import from "@langchain/redis" instead.
* Represents a specific implementation of a caching mechanism using Redis
* as the underlying storage system. It extends the `BaseCache` class and
* overrides its methods to provide the Redis-specific logic.
Expand Down
2 changes: 2 additions & 0 deletions langchain/src/stores/message/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { logVersion010MigrationWarning } from "../../util/entrypoint_deprecation

/* #__PURE__ */ logVersion010MigrationWarning({
oldEntrypointName: "stores/message/redis",
newEntrypointName: "",
newPackageName: "@langchain/redis",
});
export * from "@langchain/community/stores/message/redis";
2 changes: 2 additions & 0 deletions langchain/src/vectorstores/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js

/* #__PURE__ */ logVersion010MigrationWarning({
oldEntrypointName: "vectorstores/redis",
newEntrypointName: "",
newPackageName: "@langchain/redis",
});
export * from "@langchain/community/vectorstores/redis";
2 changes: 1 addition & 1 deletion libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"pg-copy-streams": "^6.0.5",
"pickleparser": "^0.2.1",
"portkey-ai": "^0.1.11",
"redis": "^4.6.4",
"redis": "*",
"replicate": "^0.18.0",
"typeorm": "^0.3.12",
"typesense": "^1.5.3",
Expand Down
3 changes: 2 additions & 1 deletion libs/langchain-community/src/stores/message/redis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: Deprecate in favor of stores/message/ioredis.ts when LLMCache and other implementations are ported
import {
createClient,
RedisClientOptions,
Expand All @@ -15,6 +14,7 @@ import {
} from "@langchain/core/messages";

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Type for the input to the `RedisChatMessageHistory` constructor.
*/
export type RedisChatMessageHistoryInput = {
Expand All @@ -27,6 +27,7 @@ export type RedisChatMessageHistoryInput = {
};

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Class for storing chat message history using Redis. Extends the
* `BaseListChatMessageHistory` class.
* @example
Expand Down
11 changes: 10 additions & 1 deletion libs/langchain-community/src/vectorstores/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import type { EmbeddingsInterface } from "@langchain/core/embeddings";
import { VectorStore } from "@langchain/core/vectorstores";
import { Document } from "@langchain/core/documents";

// Adapated from internal redis types which aren't exported
// Adapted from internal redis types which aren't exported
/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Type for creating a schema vector field. It includes the algorithm,
* distance metric, and initial capacity.
*/
Expand All @@ -23,6 +24,7 @@ export type CreateSchemaVectorField<
INITIAL_CAP?: number;
} & A;
/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Type for creating a flat schema vector field. It extends
* CreateSchemaVectorField with a block size property.
*/
Expand All @@ -33,6 +35,7 @@ export type CreateSchemaFlatVectorField = CreateSchemaVectorField<
}
>;
/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Type for creating a HNSW schema vector field. It extends
* CreateSchemaVectorField with M, EF_CONSTRUCTION, and EF_RUNTIME
* properties.
Expand All @@ -50,16 +53,19 @@ type CreateIndexOptions = NonNullable<
Parameters<ReturnType<typeof createClient>["ft"]["create"]>[3]
>;

/** @deprecated Install and import from the "@langchain/redis" integration package instead. */
export type RedisSearchLanguages = `${NonNullable<
CreateIndexOptions["LANGUAGE"]
>}`;

/** @deprecated Install and import from the "@langchain/redis" integration package instead. */
export type RedisVectorStoreIndexOptions = Omit<
CreateIndexOptions,
"LANGUAGE"
> & { LANGUAGE?: RedisSearchLanguages };

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Interface for the configuration of the RedisVectorStore. It includes
* the Redis client, index name, index options, key prefix, content key,
* metadata key, vector key, and filter.
Expand All @@ -79,6 +85,7 @@ export interface RedisVectorStoreConfig {
}

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Interface for the options when adding documents to the
* RedisVectorStore. It includes keys and batch size.
*/
Expand All @@ -88,12 +95,14 @@ export interface RedisAddOptions {
}

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Type for the filter used in the RedisVectorStore. It is an array of
* strings.
*/
export type RedisVectorStoreFilterType = string[];

/**
* @deprecated Install and import from the "@langchain/redis" integration package instead.
* Class representing a RedisVectorStore. It extends the VectorStore class
* and includes methods for adding documents and vectors, performing
* similarity searches, managing the index, and more.
Expand Down
66 changes: 66 additions & 0 deletions libs/langchain-redis/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = {
extends: [
"airbnb-base",
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
],
parserOptions: {
ecmaVersion: 12,
parser: "@typescript-eslint/parser",
project: "./tsconfig.json",
sourceType: "module",
},
plugins: ["@typescript-eslint", "no-instanceof"],
ignorePatterns: [
".eslintrc.cjs",
"scripts",
"node_modules",
"dist",
"dist-cjs",
"*.js",
"*.cjs",
"*.d.ts",
],
rules: {
"no-process-env": 2,
"no-instanceof/no-instanceof": 2,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-shadow": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
camelcase: 0,
"class-methods-use-this": 0,
"import/extensions": [2, "ignorePackages"],
"import/no-extraneous-dependencies": [
"error",
{ devDependencies: ["**/*.test.ts"] },
],
"import/no-unresolved": 0,
"import/prefer-default-export": 0,
"keyword-spacing": "error",
"max-classes-per-file": 0,
"max-len": 0,
"no-await-in-loop": 0,
"no-bitwise": 0,
"no-console": 0,
"no-restricted-syntax": 0,
"no-shadow": 0,
"no-continue": 0,
"no-void": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"no-useless-constructor": 0,
"no-return-await": 0,
"consistent-return": 0,
"no-else-return": 0,
"func-names": 0,
"no-lonely-if": 0,
"prefer-rest-params": 0,
"new-cap": ["error", { properties: false, capIsNew: false }],
},
};
7 changes: 7 additions & 0 deletions libs/langchain-redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
index.cjs
index.js
index.d.ts
index.d.cts
node_modules
dist
.yarn
19 changes: 19 additions & 0 deletions libs/langchain-redis/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
}
10 changes: 10 additions & 0 deletions libs/langchain-redis/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"github": {
"release": true,
"autoGenerate": true,
"tokenRef": "GITHUB_TOKEN_RELEASE"
},
"npm": {
"versionArgs": ["--workspaces-update=false"]
}
}
21 changes: 21 additions & 0 deletions libs/langchain-redis/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2023 LangChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
53 changes: 53 additions & 0 deletions libs/langchain-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# @langchain/redis

This package contains the LangChain.js integrations for Redis through their SDK.

## Installation

```bash npm2yarn
npm install @langchain/redis
```

## Development

To develop the Redis package, you'll need to follow these instructions:

### Install dependencies

```bash
yarn install
```

### Build the package

```bash
yarn build
```

Or from the repo root:

```bash
yarn build --filter=@langchain/redis
```

### Run tests

Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
end in `.int.test.ts`:

```bash
$ yarn test
$ yarn test:int
```

### Lint & Format

Run the linter & formatter to ensure your code is up to standard:

```bash
yarn lint && yarn format
```

### Adding new entrypoints

If you add a new file to be exported, either import & re-export from `src/index.ts`, or add it to the `entrypoints` field in the `config` variable located inside `langchain.config.js` and run `yarn build` to generate the new entrypoint.
21 changes: 21 additions & 0 deletions libs/langchain-redis/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest/presets/default-esm",
testEnvironment: "./jest.env.cjs",
modulePathIgnorePatterns: ["dist/", "docs/"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.tsx?$": ["@swc/jest"],
},
transformIgnorePatterns: [
"/node_modules/",
"\\.pnp\\.[^\\/]+$",
"./scripts/jest-setup-after-env.js",
],
setupFiles: ["dotenv/config"],
testTimeout: 20_000,
passWithNoTests: true,
collectCoverageFrom: ["src/**/*.ts"],
};
12 changes: 12 additions & 0 deletions libs/langchain-redis/jest.env.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { TestEnvironment } = require("jest-environment-node");

class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment {
constructor(config, context) {
// Make `instanceof Float32Array` return true in tests
// to avoid https://github.com/xenova/transformers.js/issues/57 and https://github.com/jestjs/jest/issues/2549
super(config, context);
this.global.Float32Array = Float32Array;
}
}

module.exports = AdjustedTestEnvironmentToSupportFloat32Array;
Loading
Loading