@absolutejs/rag-pinecone 0.0.2
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/README.md +66 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.js +518 -0
- package/dist/index.js.map +10 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @absolutejs/rag-pinecone
|
|
2
|
+
|
|
3
|
+
Pinecone vector-store adapter for [`@absolutejs/rag`](https://github.com/absolutejs/rag).
|
|
4
|
+
Treats Pinecone as the backend boundary: server-side filtering, native vector search,
|
|
5
|
+
and explicit opt-in index provisioning helpers.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @absolutejs/rag @absolutejs/rag-pinecone @pinecone-database/pinecone
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createPineconeRAG } from '@absolutejs/rag-pinecone';
|
|
17
|
+
|
|
18
|
+
const rag = createPineconeRAG({
|
|
19
|
+
apiKey: process.env.PINECONE_API_KEY,
|
|
20
|
+
indexName: 'absolute-rag-demo',
|
|
21
|
+
namespace: 'production',
|
|
22
|
+
vector: {
|
|
23
|
+
provider: 'pinecone',
|
|
24
|
+
dimensions: 1536,
|
|
25
|
+
distanceMetric: 'cosine'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await rag.store.upsert({
|
|
30
|
+
chunks: [
|
|
31
|
+
{
|
|
32
|
+
chunkId: 'doc-1#0',
|
|
33
|
+
text: 'Pinecone stores vectors with attached metadata.',
|
|
34
|
+
title: 'Pinecone overview',
|
|
35
|
+
source: 'https://docs.pinecone.io',
|
|
36
|
+
metadata: { tags: ['vector', 'managed'] }
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const hits = await rag.collection.search({ query: 'vector database', topK: 4 });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Index provisioning
|
|
45
|
+
|
|
46
|
+
The Pinecone index is **not** auto-provisioned at runtime. For explicit, opt-in
|
|
47
|
+
provisioning use the exported helpers:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {
|
|
51
|
+
describePineconeIndex,
|
|
52
|
+
ensurePineconeIndex
|
|
53
|
+
} from '@absolutejs/rag-pinecone';
|
|
54
|
+
|
|
55
|
+
await ensurePineconeIndex({
|
|
56
|
+
apiKey: process.env.PINECONE_API_KEY,
|
|
57
|
+
indexName: 'absolute-rag-demo',
|
|
58
|
+
dimensions: 1536,
|
|
59
|
+
metric: 'cosine',
|
|
60
|
+
waitUntilReady: true
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
CC BY-NC 4.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { RAGBackendCapabilities, RAGCollection, RAGVectorStore } from '@absolutejs/rag';
|
|
2
|
+
export declare const ABSOLUTE_PINECONE_RAG_PACKAGE_NAME = "@absolutejs/rag-pinecone";
|
|
3
|
+
export declare const PINECONE_DISTANCE_METRICS: readonly ["cosine", "euclidean", "dotproduct"];
|
|
4
|
+
export type PineconeDistanceMetric = 'cosine' | 'euclidean' | 'dotproduct';
|
|
5
|
+
export type PineconeIndexClient = {
|
|
6
|
+
upsert: (records: unknown[]) => Promise<unknown>;
|
|
7
|
+
query: (input: Record<string, unknown>) => Promise<{
|
|
8
|
+
matches?: Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
score?: number;
|
|
11
|
+
values?: number[];
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
fetch: (ids: string[]) => Promise<{
|
|
16
|
+
records?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
deleteMany: (input: string[] | Record<string, unknown>) => Promise<unknown>;
|
|
19
|
+
deleteAll: () => Promise<unknown>;
|
|
20
|
+
describeIndexStats: () => Promise<{
|
|
21
|
+
totalRecordCount?: number;
|
|
22
|
+
namespaces?: Record<string, {
|
|
23
|
+
recordCount?: number;
|
|
24
|
+
}>;
|
|
25
|
+
}>;
|
|
26
|
+
namespace?: (namespace: string) => PineconeIndexClient;
|
|
27
|
+
};
|
|
28
|
+
export type PineconeRAGVectorConfig = {
|
|
29
|
+
provider: 'pinecone';
|
|
30
|
+
dimensions: number;
|
|
31
|
+
distanceMetric?: PineconeDistanceMetric;
|
|
32
|
+
};
|
|
33
|
+
export type PineconeRAGOptions = {
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
indexName?: string;
|
|
36
|
+
indexHost?: string;
|
|
37
|
+
namespace?: string;
|
|
38
|
+
client?: PineconeIndexClient;
|
|
39
|
+
vector: PineconeRAGVectorConfig;
|
|
40
|
+
embedding?: RAGVectorStore['embed'];
|
|
41
|
+
};
|
|
42
|
+
export type PineconeRAG = {
|
|
43
|
+
store: RAGVectorStore;
|
|
44
|
+
collection: RAGCollection;
|
|
45
|
+
getCapabilities: () => RAGBackendCapabilities | undefined;
|
|
46
|
+
};
|
|
47
|
+
export type PineconeServerlessSpec = {
|
|
48
|
+
serverless: {
|
|
49
|
+
cloud: 'aws' | 'gcp' | 'azure';
|
|
50
|
+
region: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export type PineconePodSpec = {
|
|
54
|
+
pod: {
|
|
55
|
+
environment: string;
|
|
56
|
+
podType: string;
|
|
57
|
+
pods?: number;
|
|
58
|
+
replicas?: number;
|
|
59
|
+
shards?: number;
|
|
60
|
+
metadataConfig?: {
|
|
61
|
+
indexed?: string[];
|
|
62
|
+
};
|
|
63
|
+
sourceCollection?: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export type PineconeIndexSpec = PineconeServerlessSpec | PineconePodSpec;
|
|
67
|
+
export type PineconeIndexDescription = {
|
|
68
|
+
name: string;
|
|
69
|
+
dimension: number;
|
|
70
|
+
metric: PineconeDistanceMetric;
|
|
71
|
+
host?: string;
|
|
72
|
+
spec?: PineconeIndexSpec;
|
|
73
|
+
status?: {
|
|
74
|
+
ready?: boolean;
|
|
75
|
+
state?: string;
|
|
76
|
+
};
|
|
77
|
+
deletionProtection?: 'enabled' | 'disabled';
|
|
78
|
+
};
|
|
79
|
+
export type DescribePineconeIndexOptions = {
|
|
80
|
+
apiKey?: string;
|
|
81
|
+
indexName: string;
|
|
82
|
+
};
|
|
83
|
+
export type EnsurePineconeIndexOptions = {
|
|
84
|
+
apiKey?: string;
|
|
85
|
+
indexName: string;
|
|
86
|
+
dimensions: number;
|
|
87
|
+
metric?: PineconeDistanceMetric;
|
|
88
|
+
spec?: PineconeIndexSpec;
|
|
89
|
+
deletionProtection?: 'enabled' | 'disabled';
|
|
90
|
+
waitUntilReady?: boolean;
|
|
91
|
+
waitTimeoutMs?: number;
|
|
92
|
+
pollIntervalMs?: number;
|
|
93
|
+
};
|
|
94
|
+
export type EnsurePineconeIndexResult = {
|
|
95
|
+
created: boolean;
|
|
96
|
+
description: PineconeIndexDescription | undefined;
|
|
97
|
+
};
|
|
98
|
+
export declare const createPineconeStore: (options: PineconeRAGOptions) => RAGVectorStore;
|
|
99
|
+
export declare const describePineconeIndex: (options: DescribePineconeIndexOptions) => Promise<PineconeIndexDescription | undefined>;
|
|
100
|
+
export declare const ensurePineconeIndex: (options: EnsurePineconeIndexOptions) => Promise<EnsurePineconeIndexResult>;
|
|
101
|
+
export declare const createPineconeRAGCollection: (options: PineconeRAGOptions) => RAGCollection;
|
|
102
|
+
export declare const createPineconeRAG: (options: PineconeRAGOptions) => PineconeRAG;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import {
|
|
6
|
+
createRAGCollection,
|
|
7
|
+
createRAGVector,
|
|
8
|
+
normalizeVector
|
|
9
|
+
} from "@absolutejs/rag";
|
|
10
|
+
var ABSOLUTE_PINECONE_RAG_PACKAGE_NAME = "@absolutejs/rag-pinecone";
|
|
11
|
+
var PINECONE_DISTANCE_METRICS = [
|
|
12
|
+
"cosine",
|
|
13
|
+
"euclidean",
|
|
14
|
+
"dotproduct"
|
|
15
|
+
];
|
|
16
|
+
var PKG = ABSOLUTE_PINECONE_RAG_PACKAGE_NAME;
|
|
17
|
+
var DEFAULT_DIMENSIONS = 1536;
|
|
18
|
+
var DEFAULT_DISTANCE_METRIC = "cosine";
|
|
19
|
+
var PINECONE_UPSERT_BATCH_SIZE = 100;
|
|
20
|
+
var PINECONE_FETCH_BATCH_SIZE = 1000;
|
|
21
|
+
var PINECONE_FILTERED_COUNT_TOPK = 1e4;
|
|
22
|
+
var RESERVED_METADATA_KEYS = new Set(["chunkId", "text", "title", "source"]);
|
|
23
|
+
var isObjectRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
var isOperatorRecord = (value) => isObjectRecord(value) && Object.keys(value).length > 0 && Object.keys(value).every((key) => key.startsWith("$"));
|
|
25
|
+
var chunkArray = (input, size) => {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (let i = 0;i < input.length; i += size) {
|
|
28
|
+
out.push(input.slice(i, i + size));
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
};
|
|
32
|
+
var resolveVectorConfig = (options) => {
|
|
33
|
+
const vector = options?.vector;
|
|
34
|
+
if (!vector || vector.provider !== "pinecone") {
|
|
35
|
+
throw new Error(`${PKG}: Pinecone RAG requires vector.provider = "pinecone"`);
|
|
36
|
+
}
|
|
37
|
+
const dimensions = vector.dimensions ?? DEFAULT_DIMENSIONS;
|
|
38
|
+
if (!Number.isInteger(dimensions) || dimensions <= 0) {
|
|
39
|
+
throw new Error(`${PKG}: vector.dimensions must be a positive integer (received ${String(dimensions)})`);
|
|
40
|
+
}
|
|
41
|
+
const distanceMetric = vector.distanceMetric ?? DEFAULT_DISTANCE_METRIC;
|
|
42
|
+
if (!PINECONE_DISTANCE_METRICS.includes(distanceMetric)) {
|
|
43
|
+
throw new Error(`${PKG}: unsupported distanceMetric "${distanceMetric}". Allowed: ${PINECONE_DISTANCE_METRICS.join(", ")}`);
|
|
44
|
+
}
|
|
45
|
+
return { provider: "pinecone", dimensions, distanceMetric };
|
|
46
|
+
};
|
|
47
|
+
var pineconeModulePromise;
|
|
48
|
+
var loadPineconeSDK = () => {
|
|
49
|
+
if (!pineconeModulePromise) {
|
|
50
|
+
pineconeModulePromise = import("@pinecone-database/pinecone").catch((error) => {
|
|
51
|
+
pineconeModulePromise = undefined;
|
|
52
|
+
throw new Error(`${PKG}: failed to load @pinecone-database/pinecone \u2014 install it as a dependency. (${error instanceof Error ? error.message : String(error)})`);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return pineconeModulePromise;
|
|
56
|
+
};
|
|
57
|
+
var resolveIndexClientFactory = (options) => {
|
|
58
|
+
const namespace = typeof options.namespace === "string" && options.namespace.length > 0 ? options.namespace : undefined;
|
|
59
|
+
let cached;
|
|
60
|
+
const applyNamespace = (idx) => {
|
|
61
|
+
if (!namespace || typeof idx.namespace !== "function")
|
|
62
|
+
return idx;
|
|
63
|
+
return idx.namespace(namespace);
|
|
64
|
+
};
|
|
65
|
+
if (options.client) {
|
|
66
|
+
const injectedClient = options.client;
|
|
67
|
+
return async () => {
|
|
68
|
+
if (cached)
|
|
69
|
+
return cached;
|
|
70
|
+
cached = applyNamespace(injectedClient);
|
|
71
|
+
return cached;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const indexName = options.indexName;
|
|
75
|
+
if (typeof indexName !== "string" || indexName.length === 0) {
|
|
76
|
+
throw new Error(`${PKG}: indexName is required when client is not provided`);
|
|
77
|
+
}
|
|
78
|
+
const apiKey = options.apiKey ?? process.env.PINECONE_API_KEY;
|
|
79
|
+
if (!apiKey) {
|
|
80
|
+
throw new Error(`${PKG}: missing Pinecone apiKey (pass options.apiKey or set PINECONE_API_KEY)`);
|
|
81
|
+
}
|
|
82
|
+
return async () => {
|
|
83
|
+
if (cached)
|
|
84
|
+
return cached;
|
|
85
|
+
const { Pinecone } = await loadPineconeSDK();
|
|
86
|
+
const pc = new Pinecone({ apiKey });
|
|
87
|
+
const baseIndex = options.indexHost ? pc.index(indexName, options.indexHost) : pc.index(indexName);
|
|
88
|
+
cached = applyNamespace(baseIndex);
|
|
89
|
+
return cached;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
var sanitizeMetadataValue = (value) => {
|
|
93
|
+
if (value === null || value === undefined)
|
|
94
|
+
return;
|
|
95
|
+
if (typeof value === "string" || typeof value === "boolean")
|
|
96
|
+
return value;
|
|
97
|
+
if (typeof value === "number") {
|
|
98
|
+
return Number.isFinite(value) ? value : undefined;
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
const strings = [];
|
|
102
|
+
for (const entry of value) {
|
|
103
|
+
if (entry === null || entry === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
if (typeof entry === "string") {
|
|
106
|
+
strings.push(entry);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (typeof entry === "number" && Number.isFinite(entry)) {
|
|
110
|
+
strings.push(String(entry));
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (typeof entry === "boolean") {
|
|
114
|
+
strings.push(String(entry));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return strings;
|
|
119
|
+
}
|
|
120
|
+
if (typeof value === "object") {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.stringify(value);
|
|
123
|
+
} catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
};
|
|
129
|
+
var sanitizeMetadata = (metadata) => {
|
|
130
|
+
if (!isObjectRecord(metadata))
|
|
131
|
+
return {};
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
134
|
+
if (RESERVED_METADATA_KEYS.has(key))
|
|
135
|
+
continue;
|
|
136
|
+
const sanitized = sanitizeMetadataValue(value);
|
|
137
|
+
if (sanitized === undefined)
|
|
138
|
+
continue;
|
|
139
|
+
out[key] = sanitized;
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
};
|
|
143
|
+
var translateOperatorFilter = (field, operatorRecord) => {
|
|
144
|
+
const direct = {};
|
|
145
|
+
const expanded = [];
|
|
146
|
+
for (const [op, value] of Object.entries(operatorRecord)) {
|
|
147
|
+
switch (op) {
|
|
148
|
+
case "$eq":
|
|
149
|
+
case "$ne":
|
|
150
|
+
case "$gt":
|
|
151
|
+
case "$gte":
|
|
152
|
+
case "$lt":
|
|
153
|
+
case "$lte":
|
|
154
|
+
direct[op] = value;
|
|
155
|
+
break;
|
|
156
|
+
case "$in":
|
|
157
|
+
if (Array.isArray(value))
|
|
158
|
+
direct.$in = value;
|
|
159
|
+
break;
|
|
160
|
+
case "$exists":
|
|
161
|
+
direct.$exists = Boolean(value);
|
|
162
|
+
break;
|
|
163
|
+
case "$contains":
|
|
164
|
+
direct.$in = [value];
|
|
165
|
+
break;
|
|
166
|
+
case "$containsAny":
|
|
167
|
+
if (Array.isArray(value))
|
|
168
|
+
direct.$in = value;
|
|
169
|
+
break;
|
|
170
|
+
case "$containsAll":
|
|
171
|
+
if (Array.isArray(value)) {
|
|
172
|
+
for (const entry of value) {
|
|
173
|
+
expanded.push({ [field]: { $in: [entry] } });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
throw new Error(`${PKG}: unsupported filter operator "${op}"`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (expanded.length === 0) {
|
|
182
|
+
return Object.keys(direct).length > 0 ? { [field]: direct } : undefined;
|
|
183
|
+
}
|
|
184
|
+
if (Object.keys(direct).length === 0) {
|
|
185
|
+
return expanded.length === 1 ? expanded[0] : { $and: expanded };
|
|
186
|
+
}
|
|
187
|
+
return { $and: [{ [field]: direct }, ...expanded] };
|
|
188
|
+
};
|
|
189
|
+
var translateFilter = (filter) => {
|
|
190
|
+
if (!isObjectRecord(filter) || Object.keys(filter).length === 0) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const clauses = [];
|
|
194
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
195
|
+
if (key === "$and" || key === "$or") {
|
|
196
|
+
if (!Array.isArray(value))
|
|
197
|
+
continue;
|
|
198
|
+
const subs = value.map((entry) => translateFilter(entry)).filter((entry) => entry !== undefined);
|
|
199
|
+
if (subs.length > 0)
|
|
200
|
+
clauses.push({ [key]: subs });
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (key === "$not") {
|
|
204
|
+
throw new Error(`${PKG}: $not is not supported by Pinecone`);
|
|
205
|
+
}
|
|
206
|
+
if (key.includes(".")) {
|
|
207
|
+
throw new Error(`${PKG}: nested key paths ("${key}") are not supported by Pinecone (metadata is flat)`);
|
|
208
|
+
}
|
|
209
|
+
if (isOperatorRecord(value)) {
|
|
210
|
+
const translated = translateOperatorFilter(key, value);
|
|
211
|
+
if (translated)
|
|
212
|
+
clauses.push(translated);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
clauses.push({ [key]: { $eq: value } });
|
|
216
|
+
}
|
|
217
|
+
if (clauses.length === 0)
|
|
218
|
+
return;
|
|
219
|
+
if (clauses.length === 1)
|
|
220
|
+
return clauses[0];
|
|
221
|
+
return { $and: clauses };
|
|
222
|
+
};
|
|
223
|
+
var scoreForMetric = (rawScore, distanceMetric) => {
|
|
224
|
+
if (typeof rawScore !== "number" || !Number.isFinite(rawScore))
|
|
225
|
+
return 0;
|
|
226
|
+
switch (distanceMetric) {
|
|
227
|
+
case "euclidean":
|
|
228
|
+
return 1 / (1 + Math.abs(rawScore));
|
|
229
|
+
case "dotproduct":
|
|
230
|
+
case "cosine":
|
|
231
|
+
default:
|
|
232
|
+
return rawScore;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var buildPineconeRecord = (chunk, values) => {
|
|
236
|
+
const metadata = {
|
|
237
|
+
...sanitizeMetadata(chunk.metadata),
|
|
238
|
+
chunkId: chunk.chunkId,
|
|
239
|
+
text: chunk.text
|
|
240
|
+
};
|
|
241
|
+
if (chunk.title)
|
|
242
|
+
metadata.title = chunk.title;
|
|
243
|
+
if (chunk.source)
|
|
244
|
+
metadata.source = chunk.source;
|
|
245
|
+
return { id: chunk.chunkId, values, metadata };
|
|
246
|
+
};
|
|
247
|
+
var extractQueryResult = (match, distanceMetric) => {
|
|
248
|
+
const meta = isObjectRecord(match.metadata) ? match.metadata : {};
|
|
249
|
+
const userMetadata = {};
|
|
250
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
251
|
+
if (RESERVED_METADATA_KEYS.has(key))
|
|
252
|
+
continue;
|
|
253
|
+
userMetadata[key] = value;
|
|
254
|
+
}
|
|
255
|
+
const chunkId = typeof meta.chunkId === "string" ? meta.chunkId : String(match.id);
|
|
256
|
+
const chunkText = typeof meta.text === "string" ? meta.text : "";
|
|
257
|
+
return {
|
|
258
|
+
chunkId,
|
|
259
|
+
chunkText,
|
|
260
|
+
title: typeof meta.title === "string" ? meta.title : undefined,
|
|
261
|
+
source: typeof meta.source === "string" ? meta.source : undefined,
|
|
262
|
+
metadata: Object.keys(userMetadata).length > 0 ? userMetadata : undefined,
|
|
263
|
+
score: scoreForMetric(match.score, distanceMetric)
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
var createPineconeStore = (options) => {
|
|
267
|
+
const vector = resolveVectorConfig(options ?? {});
|
|
268
|
+
const namespace = typeof options.namespace === "string" && options.namespace.length > 0 ? options.namespace : undefined;
|
|
269
|
+
const getClient = resolveIndexClientFactory(options ?? {});
|
|
270
|
+
const embed = async (input) => {
|
|
271
|
+
if (typeof options.embedding === "function") {
|
|
272
|
+
const result = await options.embedding(input);
|
|
273
|
+
return normalizeVector(result);
|
|
274
|
+
}
|
|
275
|
+
return normalizeVector([
|
|
276
|
+
...createRAGVector(input.text, vector.dimensions)
|
|
277
|
+
]);
|
|
278
|
+
};
|
|
279
|
+
const upsert = async (input) => {
|
|
280
|
+
if (!input?.chunks || input.chunks.length === 0)
|
|
281
|
+
return;
|
|
282
|
+
const client = await getClient();
|
|
283
|
+
const records = await Promise.all(input.chunks.map(async (chunk) => {
|
|
284
|
+
const values = Array.isArray(chunk.embedding) && chunk.embedding.length > 0 ? normalizeVector(chunk.embedding) : await embed({ text: chunk.text });
|
|
285
|
+
return buildPineconeRecord(chunk, values);
|
|
286
|
+
}));
|
|
287
|
+
for (const batch of chunkArray(records, PINECONE_UPSERT_BATCH_SIZE)) {
|
|
288
|
+
await client.upsert(batch);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const query = async (input) => {
|
|
292
|
+
const client = await getClient();
|
|
293
|
+
const filter = translateFilter(input.filter);
|
|
294
|
+
const queryInput = {
|
|
295
|
+
vector: normalizeVector(input.queryVector),
|
|
296
|
+
topK: input.topK,
|
|
297
|
+
includeMetadata: true,
|
|
298
|
+
includeValues: false
|
|
299
|
+
};
|
|
300
|
+
if (filter)
|
|
301
|
+
queryInput.filter = filter;
|
|
302
|
+
const result = await client.query(queryInput);
|
|
303
|
+
const matches = Array.isArray(result?.matches) ? result.matches : [];
|
|
304
|
+
return matches.map((match) => extractQueryResult(match, vector.distanceMetric));
|
|
305
|
+
};
|
|
306
|
+
const count = async (input = {}) => {
|
|
307
|
+
const client = await getClient();
|
|
308
|
+
if (Array.isArray(input.chunkIds) && input.chunkIds.length > 0) {
|
|
309
|
+
let total = 0;
|
|
310
|
+
for (const batch of chunkArray(input.chunkIds, PINECONE_FETCH_BATCH_SIZE)) {
|
|
311
|
+
const response = await client.fetch(batch);
|
|
312
|
+
total += Object.keys(response?.records ?? {}).length;
|
|
313
|
+
}
|
|
314
|
+
return total;
|
|
315
|
+
}
|
|
316
|
+
if (isObjectRecord(input.filter) && Object.keys(input.filter).length > 0) {
|
|
317
|
+
const filter = translateFilter(input.filter);
|
|
318
|
+
const probeVector = new Array(vector.dimensions).fill(0);
|
|
319
|
+
const queryInput = {
|
|
320
|
+
vector: probeVector,
|
|
321
|
+
topK: PINECONE_FILTERED_COUNT_TOPK,
|
|
322
|
+
includeMetadata: false,
|
|
323
|
+
includeValues: false
|
|
324
|
+
};
|
|
325
|
+
if (filter)
|
|
326
|
+
queryInput.filter = filter;
|
|
327
|
+
const result = await client.query(queryInput);
|
|
328
|
+
return Array.isArray(result?.matches) ? result.matches.length : 0;
|
|
329
|
+
}
|
|
330
|
+
const stats = await client.describeIndexStats();
|
|
331
|
+
if (namespace) {
|
|
332
|
+
return stats?.namespaces?.[namespace]?.recordCount ?? 0;
|
|
333
|
+
}
|
|
334
|
+
return stats?.totalRecordCount ?? 0;
|
|
335
|
+
};
|
|
336
|
+
const remove = async (input = {}) => {
|
|
337
|
+
const client = await getClient();
|
|
338
|
+
if (Array.isArray(input.chunkIds) && input.chunkIds.length > 0) {
|
|
339
|
+
for (const batch of chunkArray(input.chunkIds, PINECONE_FETCH_BATCH_SIZE)) {
|
|
340
|
+
try {
|
|
341
|
+
await client.deleteMany(batch);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (!isPineconeNotFound(error))
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return input.chunkIds.length;
|
|
348
|
+
}
|
|
349
|
+
if (isObjectRecord(input.filter) && Object.keys(input.filter).length > 0) {
|
|
350
|
+
const filter = translateFilter(input.filter);
|
|
351
|
+
if (!filter)
|
|
352
|
+
return 0;
|
|
353
|
+
const counted = await count({ filter: input.filter });
|
|
354
|
+
try {
|
|
355
|
+
await client.deleteMany({ filter });
|
|
356
|
+
} catch (error) {
|
|
357
|
+
if (!isPineconeNotFound(error))
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
return counted;
|
|
361
|
+
}
|
|
362
|
+
return 0;
|
|
363
|
+
};
|
|
364
|
+
const clear = async () => {
|
|
365
|
+
const client = await getClient();
|
|
366
|
+
try {
|
|
367
|
+
await client.deleteAll();
|
|
368
|
+
} catch (error) {
|
|
369
|
+
if (!isPineconeNotFound(error))
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
return {
|
|
374
|
+
embed,
|
|
375
|
+
query,
|
|
376
|
+
upsert,
|
|
377
|
+
count,
|
|
378
|
+
delete: remove,
|
|
379
|
+
clear,
|
|
380
|
+
getCapabilities: () => ({
|
|
381
|
+
backend: "custom",
|
|
382
|
+
persistence: "external",
|
|
383
|
+
nativeVectorSearch: true,
|
|
384
|
+
serverSideFiltering: true,
|
|
385
|
+
streamingIngestStatus: false
|
|
386
|
+
})
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
var DEFAULT_INDEX_READY_TIMEOUT_MS = 120000;
|
|
390
|
+
var DEFAULT_INDEX_READY_POLL_MS = 1500;
|
|
391
|
+
var DEFAULT_SERVERLESS_SPEC = {
|
|
392
|
+
serverless: { cloud: "aws", region: "us-east-1" }
|
|
393
|
+
};
|
|
394
|
+
var isPineconeNotFound = (error) => {
|
|
395
|
+
if (!error)
|
|
396
|
+
return false;
|
|
397
|
+
const err = error;
|
|
398
|
+
const status = err.status ?? err.statusCode ?? err.response?.status ?? undefined;
|
|
399
|
+
if (status === 404)
|
|
400
|
+
return true;
|
|
401
|
+
const name = String(err.name ?? "");
|
|
402
|
+
if (name === "PineconeNotFoundError")
|
|
403
|
+
return true;
|
|
404
|
+
const message = String(err.message ?? "").toLowerCase();
|
|
405
|
+
return message.includes("not found") || message.includes("does not exist") || message.includes("404");
|
|
406
|
+
};
|
|
407
|
+
var resolveProvisioningClient = async (options) => {
|
|
408
|
+
const apiKey = options.apiKey ?? process.env.PINECONE_API_KEY;
|
|
409
|
+
if (!apiKey) {
|
|
410
|
+
throw new Error(`${PKG}: missing Pinecone apiKey (pass options.apiKey or set PINECONE_API_KEY)`);
|
|
411
|
+
}
|
|
412
|
+
if (typeof options.indexName !== "string" || options.indexName.length === 0) {
|
|
413
|
+
throw new Error(`${PKG}: indexName is required`);
|
|
414
|
+
}
|
|
415
|
+
const { Pinecone } = await loadPineconeSDK();
|
|
416
|
+
return new Pinecone({ apiKey });
|
|
417
|
+
};
|
|
418
|
+
var waitForIndexReady = async (pc, indexName, timeoutMs, pollIntervalMs) => {
|
|
419
|
+
const deadline = Date.now() + timeoutMs;
|
|
420
|
+
for (;; ) {
|
|
421
|
+
const description = await pc.describeIndex(indexName);
|
|
422
|
+
const status = description?.status;
|
|
423
|
+
const ready = status?.ready === true || status?.state === "Ready" || status?.state === "ScalingUp";
|
|
424
|
+
if (ready)
|
|
425
|
+
return description;
|
|
426
|
+
if (Date.now() >= deadline) {
|
|
427
|
+
throw new Error(`${PKG}: index "${indexName}" did not become ready within ${timeoutMs}ms (last state: ${status?.state ?? "unknown"})`);
|
|
428
|
+
}
|
|
429
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var describePineconeIndex = async (options) => {
|
|
433
|
+
const pc = await resolveProvisioningClient(options);
|
|
434
|
+
try {
|
|
435
|
+
return await pc.describeIndex(options.indexName);
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (isPineconeNotFound(error))
|
|
438
|
+
return;
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
var ensurePineconeIndex = async (options) => {
|
|
443
|
+
if (!Number.isInteger(options.dimensions) || options.dimensions <= 0) {
|
|
444
|
+
throw new Error(`${PKG}: dimensions must be a positive integer (received ${String(options.dimensions)})`);
|
|
445
|
+
}
|
|
446
|
+
const metric = options.metric ?? "cosine";
|
|
447
|
+
if (!PINECONE_DISTANCE_METRICS.includes(metric)) {
|
|
448
|
+
throw new Error(`${PKG}: unsupported metric "${metric}". Allowed: ${PINECONE_DISTANCE_METRICS.join(", ")}`);
|
|
449
|
+
}
|
|
450
|
+
const pc = await resolveProvisioningClient(options);
|
|
451
|
+
const timeoutMs = options.waitTimeoutMs ?? DEFAULT_INDEX_READY_TIMEOUT_MS;
|
|
452
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_INDEX_READY_POLL_MS;
|
|
453
|
+
const shouldWait = options.waitUntilReady !== false;
|
|
454
|
+
let existing;
|
|
455
|
+
try {
|
|
456
|
+
existing = await pc.describeIndex(options.indexName);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
if (!isPineconeNotFound(error))
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
if (existing) {
|
|
462
|
+
if (existing.dimension !== options.dimensions) {
|
|
463
|
+
throw new Error(`${PKG}: index "${options.indexName}" already exists with dimension=${existing.dimension}, but ${options.dimensions} was requested`);
|
|
464
|
+
}
|
|
465
|
+
if (existing.metric && existing.metric !== metric) {
|
|
466
|
+
throw new Error(`${PKG}: index "${options.indexName}" already exists with metric="${existing.metric}", but "${metric}" was requested`);
|
|
467
|
+
}
|
|
468
|
+
if (shouldWait && existing.status?.ready !== true) {
|
|
469
|
+
const description2 = await waitForIndexReady(pc, options.indexName, timeoutMs, pollIntervalMs);
|
|
470
|
+
return { created: false, description: description2 };
|
|
471
|
+
}
|
|
472
|
+
return { created: false, description: existing };
|
|
473
|
+
}
|
|
474
|
+
const spec = options.spec ?? DEFAULT_SERVERLESS_SPEC;
|
|
475
|
+
await pc.createIndex({
|
|
476
|
+
name: options.indexName,
|
|
477
|
+
dimension: options.dimensions,
|
|
478
|
+
metric,
|
|
479
|
+
spec,
|
|
480
|
+
...options.deletionProtection ? { deletionProtection: options.deletionProtection } : {}
|
|
481
|
+
});
|
|
482
|
+
if (!shouldWait) {
|
|
483
|
+
let description2;
|
|
484
|
+
try {
|
|
485
|
+
description2 = await pc.describeIndex(options.indexName);
|
|
486
|
+
} catch (error) {
|
|
487
|
+
if (!isPineconeNotFound(error))
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
return { created: true, description: description2 };
|
|
491
|
+
}
|
|
492
|
+
const description = await waitForIndexReady(pc, options.indexName, timeoutMs, pollIntervalMs);
|
|
493
|
+
return { created: true, description };
|
|
494
|
+
};
|
|
495
|
+
var createPineconeRAGCollection = (options) => createRAGCollection({
|
|
496
|
+
store: createPineconeStore(options)
|
|
497
|
+
});
|
|
498
|
+
var createPineconeRAG = (options) => {
|
|
499
|
+
const store = createPineconeStore(options);
|
|
500
|
+
const collection = createRAGCollection({ store });
|
|
501
|
+
return {
|
|
502
|
+
store,
|
|
503
|
+
collection,
|
|
504
|
+
getCapabilities: () => store.getCapabilities?.()
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
export {
|
|
508
|
+
ensurePineconeIndex,
|
|
509
|
+
describePineconeIndex,
|
|
510
|
+
createPineconeStore,
|
|
511
|
+
createPineconeRAGCollection,
|
|
512
|
+
createPineconeRAG,
|
|
513
|
+
PINECONE_DISTANCE_METRICS,
|
|
514
|
+
ABSOLUTE_PINECONE_RAG_PACKAGE_NAME
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
//# debugId=2B01AEA5BCA9D5E464756E2164756E21
|
|
518
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {\n\tRAGBackendCapabilities,\n\tRAGCollection,\n\tRAGQueryInput,\n\tRAGQueryResult,\n\tRAGUpsertInput,\n\tRAGVectorStore\n} from '@absolutejs/rag';\nimport {\n\tcreateRAGCollection,\n\tcreateRAGVector,\n\tnormalizeVector\n} from '@absolutejs/rag';\n\nexport const ABSOLUTE_PINECONE_RAG_PACKAGE_NAME = '@absolutejs/rag-pinecone';\n\nexport const PINECONE_DISTANCE_METRICS = [\n\t'cosine',\n\t'euclidean',\n\t'dotproduct'\n] as const;\n\nexport type PineconeDistanceMetric = 'cosine' | 'euclidean' | 'dotproduct';\n\nexport type PineconeIndexClient = {\n\tupsert: (records: unknown[]) => Promise<unknown>;\n\tquery: (input: Record<string, unknown>) => Promise<{\n\t\tmatches?: Array<{\n\t\t\tid: string;\n\t\t\tscore?: number;\n\t\t\tvalues?: number[];\n\t\t\tmetadata?: Record<string, unknown>;\n\t\t}>;\n\t}>;\n\tfetch: (ids: string[]) => Promise<{\n\t\trecords?: Record<string, unknown>;\n\t}>;\n\tdeleteMany: (input: string[] | Record<string, unknown>) => Promise<unknown>;\n\tdeleteAll: () => Promise<unknown>;\n\tdescribeIndexStats: () => Promise<{\n\t\ttotalRecordCount?: number;\n\t\tnamespaces?: Record<string, { recordCount?: number }>;\n\t}>;\n\tnamespace?: (namespace: string) => PineconeIndexClient;\n};\n\nexport type PineconeRAGVectorConfig = {\n\tprovider: 'pinecone';\n\tdimensions: number;\n\tdistanceMetric?: PineconeDistanceMetric;\n};\n\nexport type PineconeRAGOptions = {\n\tapiKey?: string;\n\tindexName?: string;\n\tindexHost?: string;\n\tnamespace?: string;\n\tclient?: PineconeIndexClient;\n\tvector: PineconeRAGVectorConfig;\n\tembedding?: RAGVectorStore['embed'];\n};\n\nexport type PineconeRAG = {\n\tstore: RAGVectorStore;\n\tcollection: RAGCollection;\n\tgetCapabilities: () => RAGBackendCapabilities | undefined;\n};\n\nexport type PineconeServerlessSpec = {\n\tserverless: {\n\t\tcloud: 'aws' | 'gcp' | 'azure';\n\t\tregion: string;\n\t};\n};\n\nexport type PineconePodSpec = {\n\tpod: {\n\t\tenvironment: string;\n\t\tpodType: string;\n\t\tpods?: number;\n\t\treplicas?: number;\n\t\tshards?: number;\n\t\tmetadataConfig?: { indexed?: string[] };\n\t\tsourceCollection?: string;\n\t};\n};\n\nexport type PineconeIndexSpec = PineconeServerlessSpec | PineconePodSpec;\n\nexport type PineconeIndexDescription = {\n\tname: string;\n\tdimension: number;\n\tmetric: PineconeDistanceMetric;\n\thost?: string;\n\tspec?: PineconeIndexSpec;\n\tstatus?: { ready?: boolean; state?: string };\n\tdeletionProtection?: 'enabled' | 'disabled';\n};\n\nexport type DescribePineconeIndexOptions = {\n\tapiKey?: string;\n\tindexName: string;\n};\n\nexport type EnsurePineconeIndexOptions = {\n\tapiKey?: string;\n\tindexName: string;\n\tdimensions: number;\n\tmetric?: PineconeDistanceMetric;\n\tspec?: PineconeIndexSpec;\n\tdeletionProtection?: 'enabled' | 'disabled';\n\twaitUntilReady?: boolean;\n\twaitTimeoutMs?: number;\n\tpollIntervalMs?: number;\n};\n\nexport type EnsurePineconeIndexResult = {\n\tcreated: boolean;\n\tdescription: PineconeIndexDescription | undefined;\n};\n\ntype ResolvedPineconeVectorConfig = {\n\tprovider: 'pinecone';\n\tdimensions: number;\n\tdistanceMetric: PineconeDistanceMetric;\n};\n\ntype MetadataValue = string | number | boolean | string[];\n\ntype PineconeRecord = {\n\tid: string;\n\tvalues: number[];\n\tmetadata: Record<string, MetadataValue>;\n};\n\ntype PineconeQueryMatch = {\n\tid: string;\n\tscore?: number;\n\tvalues?: number[];\n\tmetadata?: Record<string, unknown>;\n};\n\ntype PineconeFilter = Record<string, unknown>;\n\nconst PKG = ABSOLUTE_PINECONE_RAG_PACKAGE_NAME;\nconst DEFAULT_DIMENSIONS = 1536;\nconst DEFAULT_DISTANCE_METRIC: PineconeDistanceMetric = 'cosine';\nconst PINECONE_UPSERT_BATCH_SIZE = 100;\nconst PINECONE_FETCH_BATCH_SIZE = 1000;\nconst PINECONE_FILTERED_COUNT_TOPK = 10000;\nconst RESERVED_METADATA_KEYS = new Set(['chunkId', 'text', 'title', 'source']);\n\nconst isObjectRecord = (value: unknown): value is Record<string, unknown> =>\n\tBoolean(value) && typeof value === 'object' && !Array.isArray(value);\n\nconst isOperatorRecord = (value: unknown): value is Record<string, unknown> =>\n\tisObjectRecord(value) &&\n\tObject.keys(value).length > 0 &&\n\tObject.keys(value).every((key) => key.startsWith('$'));\n\nconst chunkArray = <T>(input: readonly T[], size: number): T[][] => {\n\tconst out: T[][] = [];\n\tfor (let i = 0; i < input.length; i += size) {\n\t\tout.push(input.slice(i, i + size));\n\t}\n\n\treturn out;\n};\n\nconst resolveVectorConfig = (\n\toptions: Partial<PineconeRAGOptions>\n): ResolvedPineconeVectorConfig => {\n\tconst vector = options?.vector;\n\tif (!vector || vector.provider !== 'pinecone') {\n\t\tthrow new Error(\n\t\t\t`${PKG}: Pinecone RAG requires vector.provider = \"pinecone\"`\n\t\t);\n\t}\n\tconst dimensions = vector.dimensions ?? DEFAULT_DIMENSIONS;\n\tif (!Number.isInteger(dimensions) || dimensions <= 0) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: vector.dimensions must be a positive integer (received ${String(\n\t\t\t\tdimensions\n\t\t\t)})`\n\t\t);\n\t}\n\tconst distanceMetric = vector.distanceMetric ?? DEFAULT_DISTANCE_METRIC;\n\tif (!PINECONE_DISTANCE_METRICS.includes(distanceMetric)) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: unsupported distanceMetric \"${distanceMetric}\". Allowed: ${PINECONE_DISTANCE_METRICS.join(\n\t\t\t\t', '\n\t\t\t)}`\n\t\t);\n\t}\n\n\treturn { provider: 'pinecone', dimensions, distanceMetric };\n};\n\ntype PineconeSDKModule = {\n\tPinecone: new (config: { apiKey: string }) => {\n\t\tindex: (name: string, host?: string) => PineconeIndexClient;\n\t\tcreateIndex: (input: Record<string, unknown>) => Promise<unknown>;\n\t\tdescribeIndex: (name: string) => Promise<PineconeIndexDescription>;\n\t};\n};\n\nlet pineconeModulePromise: Promise<PineconeSDKModule> | undefined;\nconst loadPineconeSDK = (): Promise<PineconeSDKModule> => {\n\tif (!pineconeModulePromise) {\n\t\tpineconeModulePromise = (\n\t\t\timport('@pinecone-database/pinecone') as Promise<unknown> as Promise<PineconeSDKModule>\n\t\t).catch((error: unknown) => {\n\t\t\tpineconeModulePromise = undefined;\n\t\t\tthrow new Error(\n\t\t\t\t`${PKG}: failed to load @pinecone-database/pinecone — install it as a dependency. (${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t})`\n\t\t\t);\n\t\t});\n\t}\n\n\treturn pineconeModulePromise;\n};\n\nconst resolveIndexClientFactory = (\n\toptions: PineconeRAGOptions\n): (() => Promise<PineconeIndexClient>) => {\n\tconst namespace =\n\t\ttypeof options.namespace === 'string' && options.namespace.length > 0\n\t\t\t? options.namespace\n\t\t\t: undefined;\n\n\tlet cached: PineconeIndexClient | undefined;\n\n\tconst applyNamespace = (idx: PineconeIndexClient): PineconeIndexClient => {\n\t\tif (!namespace || typeof idx.namespace !== 'function') return idx;\n\n\t\treturn idx.namespace(namespace);\n\t};\n\n\tif (options.client) {\n\t\tconst injectedClient = options.client;\n\n\t\treturn async () => {\n\t\t\tif (cached) return cached;\n\t\t\tcached = applyNamespace(injectedClient);\n\n\t\t\treturn cached;\n\t\t};\n\t}\n\n\tconst indexName = options.indexName;\n\tif (typeof indexName !== 'string' || indexName.length === 0) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: indexName is required when client is not provided`\n\t\t);\n\t}\n\tconst apiKey = options.apiKey ?? process.env.PINECONE_API_KEY;\n\tif (!apiKey) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: missing Pinecone apiKey (pass options.apiKey or set PINECONE_API_KEY)`\n\t\t);\n\t}\n\n\treturn async () => {\n\t\tif (cached) return cached;\n\t\tconst { Pinecone } = await loadPineconeSDK();\n\t\tconst pc = new Pinecone({ apiKey });\n\t\tconst baseIndex = options.indexHost\n\t\t\t? pc.index(indexName, options.indexHost)\n\t\t\t: pc.index(indexName);\n\t\tcached = applyNamespace(baseIndex);\n\n\t\treturn cached;\n\t};\n};\n\nconst sanitizeMetadataValue = (value: unknown): MetadataValue | undefined => {\n\tif (value === null || value === undefined) return undefined;\n\tif (typeof value === 'string' || typeof value === 'boolean') return value;\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : undefined;\n\t}\n\tif (Array.isArray(value)) {\n\t\tconst strings: string[] = [];\n\t\tfor (const entry of value) {\n\t\t\tif (entry === null || entry === undefined) continue;\n\t\t\tif (typeof entry === 'string') {\n\t\t\t\tstrings.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof entry === 'number' && Number.isFinite(entry)) {\n\t\t\t\tstrings.push(String(entry));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof entry === 'boolean') {\n\t\t\t\tstrings.push(String(entry));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\treturn strings;\n\t}\n\tif (typeof value === 'object') {\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nconst sanitizeMetadata = (\n\tmetadata: unknown\n): Record<string, MetadataValue> => {\n\tif (!isObjectRecord(metadata)) return {};\n\tconst out: Record<string, MetadataValue> = {};\n\tfor (const [key, value] of Object.entries(metadata)) {\n\t\tif (RESERVED_METADATA_KEYS.has(key)) continue;\n\t\tconst sanitized = sanitizeMetadataValue(value);\n\t\tif (sanitized === undefined) continue;\n\t\tout[key] = sanitized;\n\t}\n\n\treturn out;\n};\n\nconst translateOperatorFilter = (\n\tfield: string,\n\toperatorRecord: Record<string, unknown>\n): PineconeFilter | undefined => {\n\tconst direct: Record<string, unknown> = {};\n\tconst expanded: PineconeFilter[] = [];\n\tfor (const [op, value] of Object.entries(operatorRecord)) {\n\t\tswitch (op) {\n\t\t\tcase '$eq':\n\t\t\tcase '$ne':\n\t\t\tcase '$gt':\n\t\t\tcase '$gte':\n\t\t\tcase '$lt':\n\t\t\tcase '$lte':\n\t\t\t\tdirect[op] = value;\n\t\t\t\tbreak;\n\t\t\tcase '$in':\n\t\t\t\tif (Array.isArray(value)) direct.$in = value;\n\t\t\t\tbreak;\n\t\t\tcase '$exists':\n\t\t\t\tdirect.$exists = Boolean(value);\n\t\t\t\tbreak;\n\t\t\tcase '$contains':\n\t\t\t\tdirect.$in = [value];\n\t\t\t\tbreak;\n\t\t\tcase '$containsAny':\n\t\t\t\tif (Array.isArray(value)) direct.$in = value;\n\t\t\t\tbreak;\n\t\t\tcase '$containsAll':\n\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\tfor (const entry of value) {\n\t\t\t\t\t\texpanded.push({ [field]: { $in: [entry] } });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`${PKG}: unsupported filter operator \"${op}\"`);\n\t\t}\n\t}\n\tif (expanded.length === 0) {\n\t\treturn Object.keys(direct).length > 0 ? { [field]: direct } : undefined;\n\t}\n\tif (Object.keys(direct).length === 0) {\n\t\treturn expanded.length === 1 ? expanded[0] : { $and: expanded };\n\t}\n\n\treturn { $and: [{ [field]: direct }, ...expanded] };\n};\n\nconst translateFilter = (filter: unknown): PineconeFilter | undefined => {\n\tif (!isObjectRecord(filter) || Object.keys(filter).length === 0) {\n\t\treturn undefined;\n\t}\n\tconst clauses: PineconeFilter[] = [];\n\tfor (const [key, value] of Object.entries(filter)) {\n\t\tif (key === '$and' || key === '$or') {\n\t\t\tif (!Array.isArray(value)) continue;\n\t\t\tconst subs = value\n\t\t\t\t.map((entry) => translateFilter(entry))\n\t\t\t\t.filter(\n\t\t\t\t\t(entry): entry is PineconeFilter => entry !== undefined\n\t\t\t\t);\n\t\t\tif (subs.length > 0) clauses.push({ [key]: subs });\n\t\t\tcontinue;\n\t\t}\n\t\tif (key === '$not') {\n\t\t\tthrow new Error(`${PKG}: $not is not supported by Pinecone`);\n\t\t}\n\t\tif (key.includes('.')) {\n\t\t\tthrow new Error(\n\t\t\t\t`${PKG}: nested key paths (\"${key}\") are not supported by Pinecone (metadata is flat)`\n\t\t\t);\n\t\t}\n\t\tif (isOperatorRecord(value)) {\n\t\t\tconst translated = translateOperatorFilter(key, value);\n\t\t\tif (translated) clauses.push(translated);\n\t\t\tcontinue;\n\t\t}\n\t\tclauses.push({ [key]: { $eq: value } });\n\t}\n\tif (clauses.length === 0) return undefined;\n\tif (clauses.length === 1) return clauses[0];\n\n\treturn { $and: clauses };\n};\n\nconst scoreForMetric = (\n\trawScore: unknown,\n\tdistanceMetric: PineconeDistanceMetric\n): number => {\n\tif (typeof rawScore !== 'number' || !Number.isFinite(rawScore)) return 0;\n\tswitch (distanceMetric) {\n\t\tcase 'euclidean':\n\t\t\treturn 1 / (1 + Math.abs(rawScore));\n\t\tcase 'dotproduct':\n\t\tcase 'cosine':\n\t\tdefault:\n\t\t\treturn rawScore;\n\t}\n};\n\nconst buildPineconeRecord = (\n\tchunk: RAGUpsertInput['chunks'][number],\n\tvalues: number[]\n): PineconeRecord => {\n\tconst metadata: Record<string, MetadataValue> = {\n\t\t...sanitizeMetadata(chunk.metadata),\n\t\tchunkId: chunk.chunkId,\n\t\ttext: chunk.text\n\t};\n\tif (chunk.title) metadata.title = chunk.title;\n\tif (chunk.source) metadata.source = chunk.source;\n\n\treturn { id: chunk.chunkId, values, metadata };\n};\n\nconst extractQueryResult = (\n\tmatch: PineconeQueryMatch,\n\tdistanceMetric: PineconeDistanceMetric\n): RAGQueryResult => {\n\tconst meta = isObjectRecord(match.metadata) ? match.metadata : {};\n\tconst userMetadata: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(meta)) {\n\t\tif (RESERVED_METADATA_KEYS.has(key)) continue;\n\t\tuserMetadata[key] = value;\n\t}\n\tconst chunkId =\n\t\ttypeof meta.chunkId === 'string' ? meta.chunkId : String(match.id);\n\tconst chunkText = typeof meta.text === 'string' ? meta.text : '';\n\n\treturn {\n\t\tchunkId,\n\t\tchunkText,\n\t\ttitle: typeof meta.title === 'string' ? meta.title : undefined,\n\t\tsource: typeof meta.source === 'string' ? meta.source : undefined,\n\t\tmetadata:\n\t\t\tObject.keys(userMetadata).length > 0 ? userMetadata : undefined,\n\t\tscore: scoreForMetric(match.score, distanceMetric)\n\t};\n};\n\nexport const createPineconeStore = (\n\toptions: PineconeRAGOptions\n): RAGVectorStore => {\n\tconst vector = resolveVectorConfig(options ?? {});\n\tconst namespace =\n\t\ttypeof options.namespace === 'string' && options.namespace.length > 0\n\t\t\t? options.namespace\n\t\t\t: undefined;\n\tconst getClient = resolveIndexClientFactory(options ?? {});\n\n\tconst embed: RAGVectorStore['embed'] = async (input) => {\n\t\tif (typeof options.embedding === 'function') {\n\t\t\tconst result = await options.embedding(input);\n\n\t\t\treturn normalizeVector(result);\n\t\t}\n\n\t\treturn normalizeVector([\n\t\t\t...createRAGVector(input.text, vector.dimensions)\n\t\t]);\n\t};\n\n\tconst upsert = async (input: RAGUpsertInput): Promise<void> => {\n\t\tif (!input?.chunks || input.chunks.length === 0) return;\n\t\tconst client = await getClient();\n\t\tconst records = await Promise.all(\n\t\t\tinput.chunks.map(async (chunk) => {\n\t\t\t\tconst values =\n\t\t\t\t\tArray.isArray(chunk.embedding) && chunk.embedding.length > 0\n\t\t\t\t\t\t? normalizeVector(chunk.embedding)\n\t\t\t\t\t\t: await embed({ text: chunk.text });\n\n\t\t\t\treturn buildPineconeRecord(chunk, values);\n\t\t\t})\n\t\t);\n\t\tfor (const batch of chunkArray(records, PINECONE_UPSERT_BATCH_SIZE)) {\n\t\t\tawait client.upsert(batch);\n\t\t}\n\t};\n\n\tconst query = async (input: RAGQueryInput): Promise<RAGQueryResult[]> => {\n\t\tconst client = await getClient();\n\t\tconst filter = translateFilter(input.filter);\n\t\tconst queryInput: Record<string, unknown> = {\n\t\t\tvector: normalizeVector(input.queryVector),\n\t\t\ttopK: input.topK,\n\t\t\tincludeMetadata: true,\n\t\t\tincludeValues: false\n\t\t};\n\t\tif (filter) queryInput.filter = filter;\n\t\tconst result = await client.query(queryInput);\n\t\tconst matches = Array.isArray(result?.matches) ? result.matches : [];\n\n\t\treturn matches.map((match) =>\n\t\t\textractQueryResult(match, vector.distanceMetric)\n\t\t);\n\t};\n\n\tconst count = async (\n\t\tinput: { chunkIds?: string[]; filter?: Record<string, unknown> } = {}\n\t): Promise<number> => {\n\t\tconst client = await getClient();\n\t\tif (Array.isArray(input.chunkIds) && input.chunkIds.length > 0) {\n\t\t\tlet total = 0;\n\t\t\tfor (const batch of chunkArray(\n\t\t\t\tinput.chunkIds,\n\t\t\t\tPINECONE_FETCH_BATCH_SIZE\n\t\t\t)) {\n\t\t\t\tconst response = await client.fetch(batch);\n\t\t\t\ttotal += Object.keys(response?.records ?? {}).length;\n\t\t\t}\n\n\t\t\treturn total;\n\t\t}\n\t\tif (\n\t\t\tisObjectRecord(input.filter) &&\n\t\t\tObject.keys(input.filter).length > 0\n\t\t) {\n\t\t\tconst filter = translateFilter(input.filter);\n\t\t\tconst probeVector = new Array(vector.dimensions).fill(0);\n\t\t\tconst queryInput: Record<string, unknown> = {\n\t\t\t\tvector: probeVector,\n\t\t\t\ttopK: PINECONE_FILTERED_COUNT_TOPK,\n\t\t\t\tincludeMetadata: false,\n\t\t\t\tincludeValues: false\n\t\t\t};\n\t\t\tif (filter) queryInput.filter = filter;\n\t\t\tconst result = await client.query(queryInput);\n\n\t\t\treturn Array.isArray(result?.matches) ? result.matches.length : 0;\n\t\t}\n\t\tconst stats = await client.describeIndexStats();\n\t\tif (namespace) {\n\t\t\treturn stats?.namespaces?.[namespace]?.recordCount ?? 0;\n\t\t}\n\n\t\treturn stats?.totalRecordCount ?? 0;\n\t};\n\n\tconst remove = async (\n\t\tinput: { chunkIds?: string[]; filter?: Record<string, unknown> } = {}\n\t): Promise<number> => {\n\t\tconst client = await getClient();\n\t\tif (Array.isArray(input.chunkIds) && input.chunkIds.length > 0) {\n\t\t\tfor (const batch of chunkArray(\n\t\t\t\tinput.chunkIds,\n\t\t\t\tPINECONE_FETCH_BATCH_SIZE\n\t\t\t)) {\n\t\t\t\ttry {\n\t\t\t\t\tawait client.deleteMany(batch);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isPineconeNotFound(error)) throw error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn input.chunkIds.length;\n\t\t}\n\t\tif (\n\t\t\tisObjectRecord(input.filter) &&\n\t\t\tObject.keys(input.filter).length > 0\n\t\t) {\n\t\t\tconst filter = translateFilter(input.filter);\n\t\t\tif (!filter) return 0;\n\t\t\tconst counted = await count({ filter: input.filter });\n\t\t\ttry {\n\t\t\t\tawait client.deleteMany({ filter });\n\t\t\t} catch (error) {\n\t\t\t\tif (!isPineconeNotFound(error)) throw error;\n\t\t\t}\n\n\t\t\treturn counted;\n\t\t}\n\n\t\treturn 0;\n\t};\n\n\tconst clear = async (): Promise<void> => {\n\t\tconst client = await getClient();\n\t\ttry {\n\t\t\tawait client.deleteAll();\n\t\t} catch (error) {\n\t\t\tif (!isPineconeNotFound(error)) throw error;\n\t\t}\n\t};\n\n\treturn {\n\t\tembed,\n\t\tquery,\n\t\tupsert,\n\t\tcount,\n\t\tdelete: remove,\n\t\tclear,\n\t\tgetCapabilities: () => ({\n\t\t\tbackend: 'custom',\n\t\t\tpersistence: 'external',\n\t\t\tnativeVectorSearch: true,\n\t\t\tserverSideFiltering: true,\n\t\t\tstreamingIngestStatus: false\n\t\t})\n\t} as RAGVectorStore;\n};\n\nconst DEFAULT_INDEX_READY_TIMEOUT_MS = 120000;\nconst DEFAULT_INDEX_READY_POLL_MS = 1500;\nconst DEFAULT_SERVERLESS_SPEC: PineconeServerlessSpec = {\n\tserverless: { cloud: 'aws', region: 'us-east-1' }\n};\n\ntype PineconeErrorLike = {\n\tstatus?: number;\n\tstatusCode?: number;\n\tresponse?: { status?: number };\n\tname?: string;\n\tmessage?: string;\n};\n\nconst isPineconeNotFound = (error: unknown): boolean => {\n\tif (!error) return false;\n\tconst err = error as PineconeErrorLike;\n\tconst status = err.status ?? err.statusCode ?? err.response?.status ?? undefined;\n\tif (status === 404) return true;\n\tconst name = String(err.name ?? '');\n\tif (name === 'PineconeNotFoundError') return true;\n\tconst message = String(err.message ?? '').toLowerCase();\n\n\treturn (\n\t\tmessage.includes('not found') ||\n\t\tmessage.includes('does not exist') ||\n\t\tmessage.includes('404')\n\t);\n};\n\nconst resolveProvisioningClient = async (\n\toptions: DescribePineconeIndexOptions | EnsurePineconeIndexOptions\n): Promise<InstanceType<PineconeSDKModule['Pinecone']>> => {\n\tconst apiKey = options.apiKey ?? process.env.PINECONE_API_KEY;\n\tif (!apiKey) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: missing Pinecone apiKey (pass options.apiKey or set PINECONE_API_KEY)`\n\t\t);\n\t}\n\tif (\n\t\ttypeof options.indexName !== 'string' ||\n\t\toptions.indexName.length === 0\n\t) {\n\t\tthrow new Error(`${PKG}: indexName is required`);\n\t}\n\tconst { Pinecone } = await loadPineconeSDK();\n\n\treturn new Pinecone({ apiKey });\n};\n\nconst waitForIndexReady = async (\n\tpc: InstanceType<PineconeSDKModule['Pinecone']>,\n\tindexName: string,\n\ttimeoutMs: number,\n\tpollIntervalMs: number\n): Promise<PineconeIndexDescription> => {\n\tconst deadline = Date.now() + timeoutMs;\n\tfor (;;) {\n\t\tconst description = await pc.describeIndex(indexName);\n\t\tconst status = description?.status;\n\t\tconst ready =\n\t\t\tstatus?.ready === true ||\n\t\t\tstatus?.state === 'Ready' ||\n\t\t\tstatus?.state === 'ScalingUp';\n\t\tif (ready) return description;\n\t\tif (Date.now() >= deadline) {\n\t\t\tthrow new Error(\n\t\t\t\t`${PKG}: index \"${indexName}\" did not become ready within ${timeoutMs}ms (last state: ${\n\t\t\t\t\tstatus?.state ?? 'unknown'\n\t\t\t\t})`\n\t\t\t);\n\t\t}\n\t\tawait new Promise((resolve) => setTimeout(resolve, pollIntervalMs));\n\t}\n};\n\nexport const describePineconeIndex = async (\n\toptions: DescribePineconeIndexOptions\n): Promise<PineconeIndexDescription | undefined> => {\n\tconst pc = await resolveProvisioningClient(options);\n\ttry {\n\t\treturn await pc.describeIndex(options.indexName);\n\t} catch (error) {\n\t\tif (isPineconeNotFound(error)) return undefined;\n\t\tthrow error;\n\t}\n};\n\nexport const ensurePineconeIndex = async (\n\toptions: EnsurePineconeIndexOptions\n): Promise<EnsurePineconeIndexResult> => {\n\tif (!Number.isInteger(options.dimensions) || options.dimensions <= 0) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: dimensions must be a positive integer (received ${String(\n\t\t\t\toptions.dimensions\n\t\t\t)})`\n\t\t);\n\t}\n\tconst metric = options.metric ?? 'cosine';\n\tif (!PINECONE_DISTANCE_METRICS.includes(metric)) {\n\t\tthrow new Error(\n\t\t\t`${PKG}: unsupported metric \"${metric}\". Allowed: ${PINECONE_DISTANCE_METRICS.join(\n\t\t\t\t', '\n\t\t\t)}`\n\t\t);\n\t}\n\tconst pc = await resolveProvisioningClient(options);\n\tconst timeoutMs = options.waitTimeoutMs ?? DEFAULT_INDEX_READY_TIMEOUT_MS;\n\tconst pollIntervalMs = options.pollIntervalMs ?? DEFAULT_INDEX_READY_POLL_MS;\n\tconst shouldWait = options.waitUntilReady !== false;\n\n\tlet existing: PineconeIndexDescription | undefined;\n\ttry {\n\t\texisting = await pc.describeIndex(options.indexName);\n\t} catch (error) {\n\t\tif (!isPineconeNotFound(error)) throw error;\n\t}\n\n\tif (existing) {\n\t\tif (existing.dimension !== options.dimensions) {\n\t\t\tthrow new Error(\n\t\t\t\t`${PKG}: index \"${options.indexName}\" already exists with dimension=${existing.dimension}, but ${options.dimensions} was requested`\n\t\t\t);\n\t\t}\n\t\tif (existing.metric && existing.metric !== metric) {\n\t\t\tthrow new Error(\n\t\t\t\t`${PKG}: index \"${options.indexName}\" already exists with metric=\"${existing.metric}\", but \"${metric}\" was requested`\n\t\t\t);\n\t\t}\n\t\tif (shouldWait && existing.status?.ready !== true) {\n\t\t\tconst description = await waitForIndexReady(\n\t\t\t\tpc,\n\t\t\t\toptions.indexName,\n\t\t\t\ttimeoutMs,\n\t\t\t\tpollIntervalMs\n\t\t\t);\n\n\t\t\treturn { created: false, description };\n\t\t}\n\n\t\treturn { created: false, description: existing };\n\t}\n\n\tconst spec = options.spec ?? DEFAULT_SERVERLESS_SPEC;\n\tawait pc.createIndex({\n\t\tname: options.indexName,\n\t\tdimension: options.dimensions,\n\t\tmetric,\n\t\tspec,\n\t\t...(options.deletionProtection\n\t\t\t? { deletionProtection: options.deletionProtection }\n\t\t\t: {})\n\t});\n\n\tif (!shouldWait) {\n\t\tlet description: PineconeIndexDescription | undefined;\n\t\ttry {\n\t\t\tdescription = await pc.describeIndex(options.indexName);\n\t\t} catch (error) {\n\t\t\tif (!isPineconeNotFound(error)) throw error;\n\t\t}\n\n\t\treturn { created: true, description };\n\t}\n\n\tconst description = await waitForIndexReady(\n\t\tpc,\n\t\toptions.indexName,\n\t\ttimeoutMs,\n\t\tpollIntervalMs\n\t);\n\n\treturn { created: true, description };\n};\n\nexport const createPineconeRAGCollection = (\n\toptions: PineconeRAGOptions\n): RAGCollection =>\n\tcreateRAGCollection({\n\t\tstore: createPineconeStore(options)\n\t});\n\nexport const createPineconeRAG = (options: PineconeRAGOptions): PineconeRAG => {\n\tconst store = createPineconeStore(options);\n\tconst collection = createRAGCollection({ store });\n\n\treturn {\n\t\tstore,\n\t\tcollection,\n\t\tgetCapabilities: () => store.getCapabilities?.()\n\t};\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;AAQA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,qCAAqC;AAE3C,IAAM,4BAA4B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACD;AA4HA,IAAM,MAAM;AACZ,IAAM,qBAAqB;AAC3B,IAAM,0BAAkD;AACxD,IAAM,6BAA6B;AACnC,IAAM,4BAA4B;AAClC,IAAM,+BAA+B;AACrC,IAAM,yBAAyB,IAAI,IAAI,CAAC,WAAW,QAAQ,SAAS,QAAQ,CAAC;AAE7E,IAAM,iBAAiB,CAAC,UACvB,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM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AAAA,IACN;AAAA,IACA;AAAA,IACA,iBAAiB,MAAM,MAAM,kBAAkB;AAAA,EAChD;AAAA;",
|
|
8
|
+
"debugId": "2B01AEA5BCA9D5E464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@absolutejs/rag-pinecone",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Pinecone vector-store adapter for @absolutejs/rag",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/absolutejs/rag-adapters.git",
|
|
8
|
+
"directory": "pinecone"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"license": "CC BY-NC 4.0",
|
|
15
|
+
"author": "Alex Kahn",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"absolutejs",
|
|
21
|
+
"rag",
|
|
22
|
+
"pinecone",
|
|
23
|
+
"vector"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --sourcemap --target=bun --external @absolutejs/rag --external @pinecone-database/pinecone && tsc --project tsconfig.build.json",
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"format": "prettier --write \"./**/*.{ts,json,md}\"",
|
|
30
|
+
"release": "bun run format && bun run build && bun publish"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@absolutejs/rag": "^0.0.19"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@pinecone-database/pinecone": ">=5.0.0 <7.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@pinecone-database/pinecone": ">=5.0.0 <7.0.0",
|
|
40
|
+
"@types/bun": "1.2.9",
|
|
41
|
+
"prettier": "3.5.3",
|
|
42
|
+
"typescript": "5.8.3"
|
|
43
|
+
},
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": "./dist/index.js",
|
|
48
|
+
"default": "./dist/index.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"README.md"
|
|
54
|
+
]
|
|
55
|
+
}
|