@typegraph-ai/adapter-redis-upstash 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TypeGraph
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# @typegraph-ai/adapter-redis-upstash
|
|
2
|
+
|
|
3
|
+
Upstash Redis coreference-cache adapter for self-hosted TypeGraph deployments.
|
|
4
|
+
|
|
5
|
+
This package is a small Upstash-friendly wrapper around
|
|
6
|
+
`@typegraph-ai/adapter-redis`. It provides the same extraction coreference cache
|
|
7
|
+
behavior, but its option names and examples are written for `@upstash/redis`.
|
|
8
|
+
|
|
9
|
+
Cloud users do not configure this adapter. TypeGraph Cloud manages extraction
|
|
10
|
+
cache infrastructure for hosted API-key clients.
|
|
11
|
+
|
|
12
|
+
## What It Does
|
|
13
|
+
|
|
14
|
+
TypeGraph graph extraction often runs over many chunks, documents, event
|
|
15
|
+
payloads, attached transcripts, and thread turns. The extractor needs continuity:
|
|
16
|
+
if one chunk resolves `Acme Inc.` to an organization entity, later chunks should
|
|
17
|
+
reuse that context instead of treating every mention as a fresh candidate.
|
|
18
|
+
|
|
19
|
+
This adapter stores a temporary, compact list of recently extracted entities in
|
|
20
|
+
Upstash Redis. TypeGraph passes those entities back into subsequent extraction
|
|
21
|
+
calls as coreference context.
|
|
22
|
+
|
|
23
|
+
It helps with:
|
|
24
|
+
|
|
25
|
+
- consistent entity resolution across chunked documents;
|
|
26
|
+
- event extraction with attached documents;
|
|
27
|
+
- thread-turn extraction;
|
|
28
|
+
- multi-worker and serverless ingestion jobs;
|
|
29
|
+
- retries where the extractor benefits from prior context.
|
|
30
|
+
|
|
31
|
+
It does not store TypeGraph documents, memories, facts, graph edges, embeddings,
|
|
32
|
+
jobs, or buckets. Use `@typegraph-ai/adapter-pgvector` for TypeGraph storage.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @typegraph-ai/adapter-redis-upstash @upstash/redis
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`@typegraph-ai/adapter-redis-upstash` depends on
|
|
41
|
+
`@typegraph-ai/adapter-redis`, so you do not need to import the base Redis
|
|
42
|
+
adapter directly unless you are using a different Redis client.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { Redis } from '@upstash/redis'
|
|
48
|
+
import { typegraphInit } from '@typegraph-ai/sdk'
|
|
49
|
+
import { createUpstashCoreferenceCache } from '@typegraph-ai/adapter-redis-upstash'
|
|
50
|
+
|
|
51
|
+
const redis = new Redis({
|
|
52
|
+
url: process.env.UPSTASH_REDIS_REST_URL!,
|
|
53
|
+
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const typegraph = await typegraphInit({
|
|
57
|
+
vectorStore,
|
|
58
|
+
embedding,
|
|
59
|
+
searchEmbedding,
|
|
60
|
+
llm,
|
|
61
|
+
extractionCoreferenceCache: createUpstashCoreferenceCache({
|
|
62
|
+
redis,
|
|
63
|
+
namespace: 'tenant_public',
|
|
64
|
+
ttlSeconds: 4 * 60 * 60,
|
|
65
|
+
}),
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`tenantId` defaults to `public` when omitted. For multi-tenant self-hosted apps,
|
|
70
|
+
include your schema, environment, or tenant in `namespace`:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
extractionCoreferenceCache: createUpstashCoreferenceCache({
|
|
74
|
+
redis,
|
|
75
|
+
namespace: `prod:${schemaName}:${tenantId}`,
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## TypeGraph App Usage
|
|
80
|
+
|
|
81
|
+
The TypeGraph Cloud app uses this package only for its own self-hosted backend
|
|
82
|
+
runtime. End users of TypeGraph Cloud should not configure Redis.
|
|
83
|
+
|
|
84
|
+
Example app wrapper:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { Redis } from '@upstash/redis'
|
|
88
|
+
import { createUpstashCoreferenceCache } from '@typegraph-ai/adapter-redis-upstash'
|
|
89
|
+
|
|
90
|
+
export function createCoreferenceCache(schema: string, tenantId = 'public') {
|
|
91
|
+
const url = process.env.UPSTASH_REDIS_REST_URL
|
|
92
|
+
const token = process.env.UPSTASH_REDIS_REST_TOKEN
|
|
93
|
+
if (!url || !token) return undefined
|
|
94
|
+
|
|
95
|
+
return createUpstashCoreferenceCache({
|
|
96
|
+
redis: new Redis({ url, token }),
|
|
97
|
+
namespace: `${schema}:${tenantId}`,
|
|
98
|
+
onError(error) {
|
|
99
|
+
console.warn('TypeGraph coreference cache unavailable', error)
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Options
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
type UpstashCoreferenceCacheOptions = {
|
|
109
|
+
redis: Redis
|
|
110
|
+
namespace?: string
|
|
111
|
+
ttlSeconds?: number
|
|
112
|
+
maxEntities?: number
|
|
113
|
+
maxAliases?: number
|
|
114
|
+
maxTypeCandidates?: number
|
|
115
|
+
onError?: (error: unknown) => void
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `redis`
|
|
120
|
+
|
|
121
|
+
Required `@upstash/redis` client or compatible object with `get` and `set`
|
|
122
|
+
methods.
|
|
123
|
+
|
|
124
|
+
### `namespace`
|
|
125
|
+
|
|
126
|
+
Optional logical prefix for cache keys. Use this to isolate deployments,
|
|
127
|
+
schemas, tenants, or test runs.
|
|
128
|
+
|
|
129
|
+
### `ttlSeconds`
|
|
130
|
+
|
|
131
|
+
How long cache entries live. Defaults to 4 hours.
|
|
132
|
+
|
|
133
|
+
The cache is intentionally temporary. TypeGraph’s durable state still lives in
|
|
134
|
+
the configured TypeGraph storage adapter.
|
|
135
|
+
|
|
136
|
+
### `maxEntities`, `maxAliases`, `maxTypeCandidates`
|
|
137
|
+
|
|
138
|
+
Compaction limits applied before saving:
|
|
139
|
+
|
|
140
|
+
- `maxEntities`: default `120`
|
|
141
|
+
- `maxAliases`: default `12`
|
|
142
|
+
- `maxTypeCandidates`: default `4`
|
|
143
|
+
|
|
144
|
+
### `onError`
|
|
145
|
+
|
|
146
|
+
Optional error callback. Cache failures are swallowed after this hook runs, so
|
|
147
|
+
Redis downtime does not fail an otherwise valid ingest request.
|
|
148
|
+
|
|
149
|
+
## When To Use This
|
|
150
|
+
|
|
151
|
+
Use this package when:
|
|
152
|
+
|
|
153
|
+
- you self-host TypeGraph or TypeGraph Cloud backend code;
|
|
154
|
+
- extraction runs across multiple workers or serverless invocations;
|
|
155
|
+
- you want better entity continuity during graph extraction;
|
|
156
|
+
- Upstash Redis is already part of your infrastructure.
|
|
157
|
+
|
|
158
|
+
Do not use it when:
|
|
159
|
+
|
|
160
|
+
- you are a TypeGraph Cloud customer using only an API key;
|
|
161
|
+
- you need a vector database, graph database, or job queue;
|
|
162
|
+
- you want permanent memory storage.
|
|
163
|
+
|
|
164
|
+
## Related Packages
|
|
165
|
+
|
|
166
|
+
- `@typegraph-ai/adapter-redis`: generic Redis-compatible cache adapter.
|
|
167
|
+
- `@typegraph-ai/adapter-pgvector`: Postgres/pgvector TypeGraph storage adapter.
|
|
168
|
+
- `@typegraph-ai/sdk`: TypeGraph SDK.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RedisCoreferenceCacheOptions, type RedisCoreferenceClient } from '@typegraph-ai/adapter-redis';
|
|
2
|
+
export interface UpstashCoreferenceClient extends RedisCoreferenceClient {
|
|
3
|
+
}
|
|
4
|
+
export interface UpstashCoreferenceCacheOptions extends Omit<RedisCoreferenceCacheOptions, 'redis'> {
|
|
5
|
+
redis: UpstashCoreferenceClient;
|
|
6
|
+
}
|
|
7
|
+
export declare function createUpstashCoreferenceCache(options: UpstashCoreferenceCacheOptions): import("@typegraph-ai/sdk").ExtractionCoreferenceCache;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC5B,MAAM,6BAA6B,CAAA;AAEpC,MAAM,WAAW,wBAAyB,SAAQ,sBAAsB;CAAG;AAE3E,MAAM,WAAW,8BAA+B,SAAQ,IAAI,CAAC,4BAA4B,EAAE,OAAO,CAAC;IACjG,KAAK,EAAE,wBAAwB,CAAA;CAChC;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,8BAA8B,0DAEpF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,GAG5B,MAAM,6BAA6B,CAAA;AAQpC,MAAM,UAAU,6BAA6B,CAAC,OAAuC;IACnF,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAA;AAC7C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typegraph-ai/adapter-redis-upstash",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@typegraph-ai/adapter-redis": "0.1.0",
|
|
20
|
+
"@typegraph-ai/sdk": "0.5.1"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@typegraph-ai/sdk": "0.5.1"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.4.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"clean": "rm -rf dist"
|
|
34
|
+
}
|
|
35
|
+
}
|