Skip to content
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
24 changes: 1 addition & 23 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ docs.metadata
# Virtual environment
env/
venv/
.python-version

# Test logs
coverage.xml
Expand Down
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -33,12 +33,61 @@ source <your-env>/bin/activate
<your-env>/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.
Expand All @@ -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
5 changes: 5 additions & 0 deletions integration.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
langchain-core==0.1.25
langchain-community==0.0.21
redis==5.0.1
numpy==1.26.4
Empty file.