diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 0cc7756..531cae2 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,9 +1,4 @@ -// 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 @@ -13,7 +8,7 @@ ":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 + ":preserveSemverRanges", ], // Synchronized with a 2 week sprint cycle and outside business hours. @@ -35,25 +30,8 @@ "dependencyDashboardLabels": [ "type: process", ], - - "constraints": { - "python": "3.11" - }, - - "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"], diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 13eb209..ada7d89 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-redis-query-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..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 @@ -43,11 +60,15 @@ 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 run: | black --check . isort --check . + - name: Run type-check run: mypy --install-types --non-interactive . 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..c57a952 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,14 @@ 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-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", ] [tool.setuptools.dynamic] @@ -22,7 +26,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..2ed6899 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +langchain-core==0.1.25 +langchain-community==0.0.21 +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