Skip to content

Commit

Permalink
feat: Add scalar storage support for DynamoDB
Browse files Browse the repository at this point in the history
This change allows GPTCache to use DynamoDB as the underlying scalar
storage for the cache.

The underlying implementation uses 2 tables:

- `gptcache_questions` - which holds all questions and session
  information.
- `gptcache_reports` - which holds the reporting information.

Normally, we would do a single table design and rollup
`gptcache_reports` into the same table as `gptcache_questions`. However,
this was not done for one key reason: billing.

In the event a lot of analytics data is being created, then table scans
for operations like `count()` and `get_ids()` would also involve reading
these reporting rows before filtering them out, resulting in higher
read costs for end users of GPTCache.

Signed-off-by: Gautham Chandra <gautham.chandra@live.com>
  • Loading branch information
gauthamchandra committed Sep 2, 2023
1 parent 651a411 commit 35d8704
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/unit_test_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
image: redis/redis-stack-server
ports:
- 6379:6379
dynamodb:
image: amazon/dynamodb-local:2.0.0
# rebinding to a different port since 8000 is a commonly used port
ports:
- 9999:8000
mongo:
image: mongo
ports:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ This module is created to extract embeddings from requests for similarity search
- [x] Support [MariaDB](https://mariadb.org/).
- [x] Support [SQL Server](https://www.microsoft.com/en-us/sql-server/).
- [x] Support [Oracle](https://www.oracle.com/).
- [x] Support [DynamoDB](https://aws.amazon.com/dynamodb/).
- [ ] Support [MongoDB](https://www.mongodb.com/).
- [ ] Support [Redis](https://redis.io/).
- [ ] Support [Minio](https://min.io/).
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Support general database
- MariaDB.
- SQL Server.
- Oracle.
- DynamoDB

> [Example code](https://github.com/zilliztech/GPTCache/blob/main/examples/data_manager/scalar_store.py)
Expand Down
1 change: 1 addition & 0 deletions examples/data_manager/scalar_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def run():
CacheBase('mariadb', sql_url='mariadb+pymysql://root:123456@127.0.0.1:3307/mysql'),
CacheBase('sqlserver', sql_url='ssql+pyodbc://sa:Strongpsw_123@127.0.0.1:1434/msdb?driver=ODBC+Driver+17+for+SQL+Server'),
CacheBase('oracle', sql_url='oracle+cx_oracle://oracle:123456@127.0.0.1:1521/?service_name=helowin&encoding=UTF-8&nencoding=UTF-8'),
CacheBase('dynamo'),
]

for scalar_store in scalar_stores:
Expand Down
Loading

0 comments on commit 35d8704

Please sign in to comment.