Skip to content

Commit 07e6ebf

Browse files
Use GLIDE synchronous API
1 parent 6d64029 commit 07e6ebf

8 files changed

Lines changed: 455 additions & 302 deletions

File tree

VALKEY_IMPLEMENTATION.md

Lines changed: 0 additions & 145 deletions
This file was deleted.

libs/aws/langchain_aws/utilities/valkey.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from __future__ import annotations
22

3-
import asyncio
43
import logging
54
from typing import TYPE_CHECKING, Any
65

76
logger = logging.getLogger(__name__)
87

98
if TYPE_CHECKING:
10-
from glide import GlideClient, GlideClusterClient
9+
from glide_sync import GlideClient, GlideClusterClient
1110

1211
GlideClientType = GlideClient | GlideClusterClient
1312

1413

15-
async def get_client(valkey_url: str, **kwargs: Any) -> GlideClientType:
14+
def get_client(valkey_url: str, **kwargs: Any) -> GlideClientType:
1615
"""Get a GLIDE client from the connection url.
1716
1817
Args:
@@ -25,13 +24,13 @@ async def get_client(valkey_url: str, **kwargs: Any) -> GlideClientType:
2524
Example:
2625
```python
2726
from langchain_aws.utilities.valkey import get_client
28-
valkey_client = await get_client(
27+
valkey_client = get_client(
2928
valkey_url="valkey://localhost:6379"
3029
)
3130
```
3231
"""
3332
try:
34-
from glide import (
33+
from glide_sync import (
3534
GlideClient,
3635
GlideClientConfiguration,
3736
GlideClusterClient,
@@ -40,8 +39,8 @@ async def get_client(valkey_url: str, **kwargs: Any) -> GlideClientType:
4039
)
4140
except ImportError:
4241
raise ImportError(
43-
"Could not import valkey-glide python package. "
44-
"Please install it with `pip install valkey-glide>=2.0.0`."
42+
"Could not import valkey-glide-sync python package. "
43+
"Please install it with `pip install valkey-glide-sync>=2.0.0`."
4544
)
4645

4746
# Parse URL
@@ -51,12 +50,12 @@ async def get_client(valkey_url: str, **kwargs: Any) -> GlideClientType:
5150
# Try cluster first
5251
try:
5352
config = GlideClusterClientConfiguration(addresses=addresses, **kwargs)
54-
client = await GlideClusterClient.create(config)
53+
client = GlideClusterClient.create(config)
5554
return client
5655
except Exception:
5756
# Fall back to standalone
5857
config = GlideClientConfiguration(addresses=addresses, **kwargs)
59-
client = await GlideClient.create(config)
58+
client = GlideClient.create(config)
6059
return client
6160

6261

libs/aws/langchain_aws/vectorstores/valkey/README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Valkey Vector Store
22

3-
This module provides a vector store implementation for [Valkey](https://valkey.io/), a Redis-compatible in-memory data store that supports vector search capabilities.
3+
This module provides a vector store implementation for [Valkey](https://valkey.io/), a Redis-compatible in-memory data store that supports vector search capabilities. Uses the [Valkey GLIDE](https://glide.valkey.io/) synchronous client for optimal performance.
44

55
## Installation
66

77
```bash
88
pip install langchain-aws[valkey]
99
```
1010

11+
This installs `valkey-glide-sync>=2.0.0` as the client library.
12+
1113
## Usage
1214

1315
### Basic Example
@@ -64,7 +66,9 @@ vectorstore = ValkeyVectorStore.from_texts(
6466
- **Vector Similarity Search**: Find similar documents using cosine similarity, L2, or inner product
6567
- **Metadata Filtering**: Filter search results using tag, numeric, and text filters
6668
- **Scalable**: Built on Valkey's high-performance architecture
67-
- **AWS Integration**: Works seamlessly with AWS ElastiCache for Valkey
69+
- **AWS Integration**: Works seamlessly with AWS ElastiCache for Valkey and Amazon MemoryDB
70+
- **Cluster Support**: Automatic detection and support for Valkey clusters
71+
- **Synchronous API**: Native sync interface using Valkey GLIDE
6872

6973
## Connection URL Formats
7074

@@ -76,10 +80,16 @@ vectorstore = ValkeyVectorStore.from_texts(
7680
## Filtering
7781

7882
```python
79-
from langchain_aws.vectorstores.valkey import ValkeyFilter
83+
from langchain_aws.vectorstores.valkey.filters import ValkeyTag, ValkeyNum, ValkeyText
84+
85+
# Tag filter
86+
filter_expr = ValkeyTag("category") == "technology"
87+
88+
# Numeric filter
89+
filter_expr = ValkeyNum("year") >= 2020
8090

81-
# Create filters
82-
filter_expr = (ValkeyFilter.tag("category") == "technology") & (ValkeyFilter.num("year") >= 2020)
91+
# Combined filters
92+
filter_expr = (ValkeyTag("category") == "technology") & (ValkeyNum("year") >= 2020)
8393

8494
# Search with filter
8595
results = vectorstore.similarity_search(
@@ -115,11 +125,17 @@ vectorstore = ValkeyVectorStore(
115125
## Requirements
116126

117127
- Python >= 3.10
118-
- valkey >= 6.0.0
119-
- Valkey server with vector search support (Valkey 8.0+)
128+
- valkey-glide-sync >= 2.0.0
129+
- Valkey server with vector search support (Valkey 8.0+ or Redis 7.2+ with RediSearch)
120130

121131
## AWS Services
122132

123133
This vector store works with:
124134
- [AWS ElastiCache for Valkey](https://aws.amazon.com/elasticache/)
125135
- [Amazon MemoryDB for Valkey](https://aws.amazon.com/memorydb/)
136+
137+
## Additional Resources
138+
139+
- [Valkey GLIDE Documentation](https://glide.valkey.io/)
140+
- [Valkey Vector Search](https://valkey.io/commands/ft.search/)
141+
- [LangChain VectorStores](https://python.langchain.com/docs/modules/data_connection/vectorstores/)

0 commit comments

Comments
 (0)