From cde9520adacd1463b4bcce06b2bfe6d912fd8350 Mon Sep 17 00:00:00 2001 From: Yuan Teoh Date: Wed, 21 Feb 2024 18:42:00 -0800 Subject: [PATCH 1/6] chore: cleanup repo --- .github/renovate.json5 | 77 ++----------------- .github/sync-repo-settings.yaml | 4 + .github/workflows/lint.yml | 3 + .gitignore | 1 + README.md | 59 +++++++++++++- integration.cloudbuild.yaml | 5 ++ pyproject.toml | 10 ++- requirements.txt | 3 + .../py.typed | 0 9 files changed, 85 insertions(+), 77 deletions(-) create mode 100644 requirements.txt create mode 100644 src/langchain_google_memorystore_redis/py.typed diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 0cc7756..39b2a0e 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,75 +1,12 @@ -// Dependency Update Configuration -// -// See https://docs.renovatebot.com/configuration-options/ -// See https://json5.org/ for JSON5 syntax { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ - "config:base", // https://docs.renovatebot.com/presets-config/#configbase - ":semanticCommits", // https://docs.renovatebot.com/presets-default/#semanticcommits - ":ignoreUnstable", // https://docs.renovatebot.com/presets-default/#ignoreunstable - "group:allNonMajor", // https://docs.renovatebot.com/presets-group/#groupallnonmajor - ":separateMajorReleases", // https://docs.renovatebot.com/presets-default/#separatemajorreleases - ":prConcurrentLimitNone", // View complete backlog as PRs. https://docs.renovatebot.com/presets-default/#prconcurrentlimitnone - ":prNotPending", // https://docs.renovatebot.com/presets-default/#prnotpending - ":prHourlyLimitNone", // https://docs.renovatebot.com/presets-default/#prhourlylimitnone - "docker:enableMajor", // https://docs.renovatebot.com/presets-docker/#dockerenablemajor + "config:base", + "group:all", + ":preserveSemverRanges", + ":disableDependencyDashboard" ], - - // Synchronized with a 2 week sprint cycle and outside business hours. - // https://docs.renovatebot.com/configuration-options/#schedule - "schedule": ["every 2 weeks on Saturday"], - - // Give ecosystem time to catch up. - // npm allows maintainers to unpublish a release up to 3 days later. - // https://docs.renovatebot.com/configuration-options/#minimumreleaseage - "minimumReleaseAge": "3", - - // Create PRs, but do not update them without manual action. - // Reduces spurious retesting in repositories that have many PRs at a time. - // https://docs.renovatebot.com/configuration-options/#rebasewhen - "rebaseWhen": "never", - - // Organizational processes. - // https://docs.renovatebot.com/configuration-options/#dependencydashboardlabels - "dependencyDashboardLabels": [ - "type: process", - ], - - "constraints": { - "python": "3.11" - }, - + "ignorePaths": [".pre-commit-config.yaml", ".kokoro/requirements.txt", "setup.py"], "pip_requirements": { - "fileMatch": ["requirements-test.txt"] - }, - "packageRules": [ - - // Tooling & Runtime behaviors. - { - // Covers Dockerfiles, cloudbuild.yaml, and other docker-based tools. - "groupName": "Docker Runtimes", - "matchDatasources": ["docker"], - // TODO: Uncomment if your Dockerfiles are not included in samples. - // Increases build repeatability, image cache use, and supply chain security. - // "pinDigests": true, - }, - { - "groupName": "GitHub Actions", - "matchManagers": ["github-actions"], - "pinDigests": true, - }, - - // Python Specific - { - "matchPackageNames": ["pytest"], - "matchUpdateTypes": ["minor", "major"] - }, - { - "groupName": "python-nonmajor", - "matchLanguages": ["python"], - "matchUpdateTypes": ["minor", "patch"], - }, - - ], + "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"] + } } diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 13eb209..83c40c4 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -26,6 +26,10 @@ branchProtectionRules: isAdminEnforced: true requiredStatusCheckContexts: - "cla/google" + - "lint" + - "integration-test-pr (langchain-memorystore-redis-testing)" + - "conventionalcommits.org" + - "header-check" # - Add required status checks like presubmit tests requiredApprovingReviewCount: 1 requiresCodeOwnerReviews: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index abf008f..d30c7c7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,6 +43,9 @@ jobs: python-version: "3.11" - name: Install requirements + run: pip install -r requirements.txt + + - name: Install module (and test requirements) run: pip install -e .[test] - name: Run linters diff --git a/.gitignore b/.gitignore index d083ea1..3c0f60e 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ docs.metadata # Virtual environment env/ venv/ +.python-version # Test logs coverage.xml diff --git a/README.md b/README.md index adc6ec3..f1c6533 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Memorystore for Redis for LangChain -*Description* +This package contains the [LangChain][langchain] integrations for Memorystore for Redis. > **🧪 Preview:** This feature is covered by the Pre-GA Offerings Terms of the Google Cloud Terms of Service. Please note that pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages) @@ -33,12 +33,61 @@ source /bin/activate /bin/pip install langchain-google-memorystore-redis ``` -## Usage +## Vector Store Usage + +Use a vector store to store embedded data and perform vector search. + +```python +from langchain_google_memorystore_redis import RedisVectorStore +from langchain_community.embeddings.fake import FakeEmbeddings + +embeddings = FakeEmbeddings(size=128) +redis_client = redis.from_url("redis://127.0.0.1:6379") + +embeddings_service = VertexAIEmbeddings() +vectorstore = RedisVectorStore( + client=redis_client, + index_name="my_vector_index", + embeddings=embeddings +) +``` + +See the full [Vector Store][vectorstore] tutorial. + +## Document Loader Usage + +Use a document loader to load data as LangChain `Document`s. + +```python +from langchain_google_memorystore_redis import MemorystoreDocumentLoader + + +loader = MemorystoreDocumentLoader( + client=redis_client, + key_prefix="docs:", + content_fields=set(["page_content"]), +) +docs = loader.lazy_load() +``` + +See the full [Document Loader][loader] tutorial. + +## Chat Message History Usage + +Use `ChatMessageHistory` to store messages and provide conversation history to LLMs. ```python -from langchain_google_memorystore_redis import RedisVectorStore, MemorystoreDocumentLoader, MemorystoreChatMessageHistory +from langchain_google_memorystore_redis import MemorystoreChatMessageHistory + + +history = MemorystoreChatMessageHistory( + client=redis_client, + session_id="my-session_id" +) ``` +See the full [Chat Message History][history] tutorial. + ## Contributing Contributions to this library are always welcome and highly encouraged. @@ -62,3 +111,7 @@ This is not an officially supported Google product. [api]: https://console.cloud.google.com/flows/enableapi?apiid=memorystore.googleapis.com [auth]: https://googleapis.dev/python/google-api-core/latest/auth.html [venv]: https://virtualenv.pypa.io/en/latest/ +[vectorstore]: ./docs/vector_store.ipynb +[loader]: ./docs/document_loader.ipynb +[history]: ./docs/chat_message_history.ipynb +[langchain]: https://github.com/langchain-ai/langchain diff --git a/integration.cloudbuild.yaml b/integration.cloudbuild.yaml index 62d8d22..cfa851b 100644 --- a/integration.cloudbuild.yaml +++ b/integration.cloudbuild.yaml @@ -14,6 +14,11 @@ steps: - id: Install dependencies + name: python:3.11 + entrypoint: pip + args: ["install", "--user", "-r", "requirements.txt"] + + - id: Install module (and test requirements) name: python:3.11 entrypoint: pip args: ["install", ".[test]", "--user"] diff --git a/pyproject.toml b/pyproject.toml index 6d0f71e..7b79f17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,13 @@ description = "LangChain integrations for Google Cloud Memorystore" readme = "README.md" license = {file = "LICENSE"} requires-python = ">=3.8" +authors = [ + {name = "Google LLC", email = "googleapis-packages@google.com"} +] dependencies = [ - "langchain==0.1.1", - "redis>=5.0.0", - "numpy>=1.21.0", + "langchain>=0.1.1, <1.0.0", + "redis>=5.0.0, <6.0.0", + "numpy>=1.21.0, <2.0.0", ] [tool.setuptools.dynamic] @@ -22,7 +25,6 @@ Changelog = "https://github.com/googleapis/langchain-google-memorystore-redis-py [project.optional-dependencies] test = [ - "black==23.12.0", "black[jupyter]==23.12.0", "isort==5.13.2", "mypy==1.7.1", diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fd263ea --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +langchain==0.1.8 +redis==5.0.1 +numpy==1.26.4 diff --git a/src/langchain_google_memorystore_redis/py.typed b/src/langchain_google_memorystore_redis/py.typed new file mode 100644 index 0000000..e69de29 From 8aeade3ed02a533919d9797c6f2b04b96c80a6cf Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 22 Feb 2024 10:06:39 -0800 Subject: [PATCH 2/6] Update renovate.json5 --- .github/renovate.json5 | 55 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 39b2a0e..531cae2 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,12 +1,53 @@ { "extends": [ - "config:base", - "group:all", + "config:base", // https://docs.renovatebot.com/presets-config/#configbase + ":semanticCommits", // https://docs.renovatebot.com/presets-default/#semanticcommits + ":ignoreUnstable", // https://docs.renovatebot.com/presets-default/#ignoreunstable + "group:allNonMajor", // https://docs.renovatebot.com/presets-group/#groupallnonmajor + ":separateMajorReleases", // https://docs.renovatebot.com/presets-default/#separatemajorreleases + ":prConcurrentLimitNone", // View complete backlog as PRs. https://docs.renovatebot.com/presets-default/#prconcurrentlimitnone + ":prNotPending", // https://docs.renovatebot.com/presets-default/#prnotpending + ":prHourlyLimitNone", // https://docs.renovatebot.com/presets-default/#prhourlylimitnone ":preserveSemverRanges", - ":disableDependencyDashboard" ], - "ignorePaths": [".pre-commit-config.yaml", ".kokoro/requirements.txt", "setup.py"], - "pip_requirements": { - "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"] - } + + // Synchronized with a 2 week sprint cycle and outside business hours. + // https://docs.renovatebot.com/configuration-options/#schedule + "schedule": ["every 2 weeks on Saturday"], + + // Give ecosystem time to catch up. + // npm allows maintainers to unpublish a release up to 3 days later. + // https://docs.renovatebot.com/configuration-options/#minimumreleaseage + "minimumReleaseAge": "3", + + // Create PRs, but do not update them without manual action. + // Reduces spurious retesting in repositories that have many PRs at a time. + // https://docs.renovatebot.com/configuration-options/#rebasewhen + "rebaseWhen": "never", + + // Organizational processes. + // https://docs.renovatebot.com/configuration-options/#dependencydashboardlabels + "dependencyDashboardLabels": [ + "type: process", + ], + "packageRules": [ + + { + "groupName": "GitHub Actions", + "matchManagers": ["github-actions"], + "pinDigests": true, + }, + + // Python Specific + { + "matchPackageNames": ["pytest"], + "matchUpdateTypes": ["minor", "major"] + }, + { + "groupName": "python-nonmajor", + "matchLanguages": ["python"], + "matchUpdateTypes": ["minor", "patch"], + }, + + ], } From 8a7ae587142d1c5c6588505bc67a6b031482a1f9 Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 22 Feb 2024 10:07:04 -0800 Subject: [PATCH 3/6] Update lint.yml --- .github/workflows/lint.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d30c7c7..9b16c1c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,6 +34,23 @@ jobs: if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" steps: + - name: Remove PR label + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.removeLabel({ + name: 'tests: run', + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + } catch (e) { + console.log('Failed to remove label. Another job may have already removed it!'); + } + - name: Checkout Repository uses: actions/checkout@v3 @@ -52,5 +69,6 @@ jobs: run: | black --check . isort --check . + - name: Run type-check run: mypy --install-types --non-interactive . From 35cd75c905d808af7b7cccc32de80e44cbe0494f Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 22 Feb 2024 10:11:15 -0800 Subject: [PATCH 4/6] Update sync-repo-settings.yaml --- .github/sync-repo-settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 83c40c4..ada7d89 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -27,7 +27,7 @@ branchProtectionRules: requiredStatusCheckContexts: - "cla/google" - "lint" - - "integration-test-pr (langchain-memorystore-redis-testing)" + - "integration-test-pr (langchain-redis-query-testing)" - "conventionalcommits.org" - "header-check" # - Add required status checks like presubmit tests From e47fb850f877753fe6439f85b778035ebb21b0aa Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 22 Feb 2024 10:11:57 -0800 Subject: [PATCH 5/6] Update pyproject.toml --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7b79f17..c57a952 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,8 @@ authors = [ {name = "Google LLC", email = "googleapis-packages@google.com"} ] dependencies = [ - "langchain>=0.1.1, <1.0.0", + "langchain-core>=0.1.1, <1.0.0", + "langchain-community>=0.0.18, <1.0.0", "redis>=5.0.0, <6.0.0", "numpy>=1.21.0, <2.0.0", ] From 1aff6eb6391a02bf7c05a7504d4ceff54e91e46a Mon Sep 17 00:00:00 2001 From: Averi Kitsch Date: Thu, 22 Feb 2024 10:16:06 -0800 Subject: [PATCH 6/6] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fd263ea..2ed6899 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -langchain==0.1.8 +langchain-core==0.1.25 +langchain-community==0.0.21 redis==5.0.1 numpy==1.26.4