@memberjunction/ai-vectors-pinecone 2.32.2 → 2.34.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.
Files changed (2) hide show
  1. package/README.md +300 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,300 @@
1
+ # @memberjunction/ai-vectors-pinecone
2
+
3
+ A MemberJunction implementation of vector database services using Pinecone as the backend. This package provides a standardized interface for working with vector embeddings, vector search, and other vector operations within the MemberJunction ecosystem.
4
+
5
+ ## Features
6
+
7
+ - **Pinecone Integration**: Seamless integration with Pinecone's vector database
8
+ - **Standardized Interface**: Follows MemberJunction's VectorDBBase abstract class
9
+ - **Index Management**: Create, delete, and query vector indexes
10
+ - **Record Operations**: Comprehensive CRUD operations for vector records
11
+ - **Namespace Support**: Work with namespaces for organization within indexes
12
+ - **Metadata Storage**: Store and query with metadata alongside vector embeddings
13
+ - **Configuration Management**: Environment-based configuration options
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @memberjunction/ai-vectors-pinecone
19
+ ```
20
+
21
+ ## Requirements
22
+
23
+ - Node.js 16+
24
+ - A Pinecone API key and account
25
+ - MemberJunction Core libraries
26
+
27
+ ## Configuration
28
+
29
+ Create a `.env` file with your Pinecone credentials:
30
+
31
+ ```bash
32
+ # Pinecone Configuration
33
+ PINECONE_API_KEY=your-pinecone-api-key
34
+ PINECONE_HOST=your-pinecone-host
35
+ PINECONE_DEFAULT_INDEX=your-default-index-name
36
+
37
+ # Optional: For embedding generation
38
+ OPENAI_API_KEY=your-openai-api-key
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Initialize the Pinecone Client
44
+
45
+ ```typescript
46
+ import { PineconeDatabase } from '@memberjunction/ai-vectors-pinecone';
47
+
48
+ // Initialize with your Pinecone API key
49
+ const pineconeDB = new PineconeDatabase('your-pinecone-api-key');
50
+ ```
51
+
52
+ ### List Available Indexes
53
+
54
+ ```typescript
55
+ // Get a list of all available indexes
56
+ const indexList = await pineconeDB.listIndexes();
57
+ console.log('Available indexes:', indexList.indexes.map(idx => idx.name));
58
+ ```
59
+
60
+ ### Create a New Index
61
+
62
+ ```typescript
63
+ // Create a new vector index
64
+ const createResult = await pineconeDB.createIndex({
65
+ id: 'my-new-index',
66
+ dimension: 1536, // Dimension for OpenAI embeddings
67
+ metric: 'cosine',
68
+ additionalParams: {
69
+ serverless: {
70
+ cloud: 'aws',
71
+ region: 'us-west-2'
72
+ }
73
+ }
74
+ });
75
+
76
+ if (createResult.success) {
77
+ console.log('Index created successfully');
78
+ } else {
79
+ console.error('Failed to create index:', createResult.message);
80
+ }
81
+ ```
82
+
83
+ ### Insert Vector Records
84
+
85
+ ```typescript
86
+ import { VectorRecord } from '@memberjunction/ai-vectordb';
87
+
88
+ // Create a single vector record
89
+ const vectorRecord: VectorRecord = {
90
+ id: 'record-123',
91
+ values: [0.1, 0.2, 0.3, /* ... rest of vector values */],
92
+ metadata: {
93
+ RecordID: '123',
94
+ Entity: 'Customer',
95
+ TemplateID: 'customer-profile',
96
+ // Additional metadata as needed
97
+ }
98
+ };
99
+
100
+ const insertResult = await pineconeDB.createRecord(vectorRecord);
101
+
102
+ if (insertResult.success) {
103
+ console.log('Record inserted successfully');
104
+ }
105
+ ```
106
+
107
+ ### Insert Multiple Records at Once
108
+
109
+ ```typescript
110
+ // Create multiple vector records in a single operation
111
+ const vectorRecords: VectorRecord[] = [
112
+ {
113
+ id: 'record-123',
114
+ values: [/* vector values */],
115
+ metadata: { RecordID: '123', Entity: 'Customer', TemplateID: 'template-1' }
116
+ },
117
+ {
118
+ id: 'record-124',
119
+ values: [/* vector values */],
120
+ metadata: { RecordID: '124', Entity: 'Customer', TemplateID: 'template-1' }
121
+ }
122
+ ];
123
+
124
+ const batchInsertResult = await pineconeDB.createRecords(vectorRecords);
125
+ ```
126
+
127
+ ### Query Vector Records
128
+
129
+ ```typescript
130
+ // Query vectors by similarity
131
+ const queryResult = await pineconeDB.queryIndex({
132
+ vector: [0.1, 0.2, 0.3, /* ... rest of query vector */],
133
+ topK: 5,
134
+ includeMetadata: true,
135
+ filter: {
136
+ Entity: { $eq: 'Customer' }
137
+ }
138
+ });
139
+
140
+ if (queryResult.success) {
141
+ console.log('Query results:', queryResult.data.matches);
142
+
143
+ // Process the matching records
144
+ queryResult.data.matches.forEach(match => {
145
+ console.log(`Match ID: ${match.id}, Score: ${match.score}`);
146
+ console.log('Metadata:', match.metadata);
147
+ });
148
+ }
149
+ ```
150
+
151
+ ### Retrieve Specific Records
152
+
153
+ ```typescript
154
+ // Fetch a specific record by ID
155
+ const getRecordResult = await pineconeDB.getRecord({
156
+ id: 'my-index-name', // Optional - uses default if not specified
157
+ data: 'record-123' // The record ID to fetch
158
+ });
159
+
160
+ if (getRecordResult.success) {
161
+ console.log('Retrieved record:', getRecordResult.data);
162
+ }
163
+ ```
164
+
165
+ ### Delete Records
166
+
167
+ ```typescript
168
+ // Delete a single record
169
+ const deleteResult = await pineconeDB.deleteRecord({
170
+ id: 'record-123'
171
+ });
172
+
173
+ // Delete multiple records
174
+ const deleteMultipleResult = await pineconeDB.deleteRecords([
175
+ { id: 'record-123' },
176
+ { id: 'record-124' }
177
+ ]);
178
+
179
+ // Delete all records in an index or namespace
180
+ const deleteAllResult = await pineconeDB.deleteAllRecords({
181
+ id: 'my-index-name', // Optional - uses default if not specified
182
+ data: 'my-namespace' // Optional - if provided, only deletes in this namespace
183
+ });
184
+ ```
185
+
186
+ ## API Reference
187
+
188
+ ### PineconeDatabase Class
189
+
190
+ The main class that implements the VectorDBBase abstract class for Pinecone.
191
+
192
+ #### Constructor
193
+
194
+ ```typescript
195
+ new PineconeDatabase(apiKey: string)
196
+ ```
197
+
198
+ #### Properties
199
+
200
+ - `pinecone`: Returns the underlying Pinecone client instance
201
+
202
+ #### Methods
203
+
204
+ ##### Index Management
205
+ - `listIndexes()`: List all available indexes
206
+ - `getIndexDescription(params)`: Get detailed information about an index
207
+ - `createIndex(options)`: Create a new vector index
208
+ - `deleteIndex(params)`: Delete an index
209
+ - `getIndex(params?)`: Get a reference to an index (uses default if not specified)
210
+ - `getDefaultIndex()`: Get the default index based on config or first available
211
+
212
+ ##### Record Operations
213
+ - `createRecord(params)`: Insert a single vector record
214
+ - `createRecords(records)`: Insert multiple vector records
215
+ - `getRecord(params)`: Retrieve a specific record by ID
216
+ - `getRecords(params)`: Retrieve multiple records by ID
217
+ - `updateRecord(params)`: Update a single record
218
+ - `deleteRecord(record)`: Delete a specific record
219
+ - `deleteRecords(records)`: Delete multiple records
220
+ - `deleteAllRecords(params)`: Delete all records in an index or namespace
221
+
222
+ ##### Querying
223
+ - `queryIndex(params)`: Query vectors by similarity
224
+
225
+ ### Key Interfaces
226
+
227
+ #### VectorRecord
228
+
229
+ ```typescript
230
+ interface VectorRecord {
231
+ id: string;
232
+ values: number[];
233
+ metadata?: RecordMetadata;
234
+ sparseValues?: { indices: number[]; values: number[] };
235
+ }
236
+ ```
237
+
238
+ #### BaseRequestParams
239
+
240
+ ```typescript
241
+ interface BaseRequestParams {
242
+ id?: string; // Index name (uses default if not provided)
243
+ data?: any; // Additional data for the operation
244
+ }
245
+ ```
246
+
247
+ #### CreateIndexParams
248
+
249
+ ```typescript
250
+ interface CreateIndexParams {
251
+ id: string; // Index name
252
+ dimension: number; // Vector dimension
253
+ metric?: string; // Distance metric (cosine, euclidean, dotproduct)
254
+ additionalParams?: any; // Additional Pinecone-specific parameters
255
+ }
256
+ ```
257
+
258
+ ## Environment Variables
259
+
260
+ | Variable | Description |
261
+ |----------|-------------|
262
+ | PINECONE_API_KEY | Your Pinecone API key |
263
+ | PINECONE_HOST | Your Pinecone host URL |
264
+ | PINECONE_DEFAULT_INDEX | Default index name to use if not specified |
265
+ | OPENAI_API_KEY | Optional: OpenAI API key for generating embeddings |
266
+
267
+ ## Integration with MemberJunction Vectors
268
+
269
+ This package works seamlessly with other MemberJunction vector packages:
270
+
271
+ ```typescript
272
+ import { PineconeDatabase } from '@memberjunction/ai-vectors-pinecone';
273
+ import { OpenAIEmbedding } from '@memberjunction/ai-openai';
274
+ import { VectorSync } from '@memberjunction/ai-vectors-sync';
275
+
276
+ // Set up your vector database
277
+ const vectorDB = new PineconeDatabase(pineconeAPIKey);
278
+
279
+ // Set up your embedding provider
280
+ const embeddingProvider = new OpenAIEmbedding(openAIAPIKey);
281
+
282
+ // Use with VectorSync for entity synchronization
283
+ const vectorSync = new VectorSync({
284
+ vectorDB: vectorDB,
285
+ embeddingProvider: embeddingProvider,
286
+ // other configuration...
287
+ });
288
+ ```
289
+
290
+ ## Dependencies
291
+
292
+ - `@memberjunction/ai-vectordb`: Base abstractions for vector databases
293
+ - `@memberjunction/aiengine`: MemberJunction AI Engine
294
+ - `@memberjunction/core`: MemberJunction core library
295
+ - `@memberjunction/global`: MemberJunction global utilities
296
+ - `@pinecone-database/pinecone`: Official Pinecone client
297
+
298
+ ## License
299
+
300
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-vectors-pinecone",
3
- "version": "2.32.2",
3
+ "version": "2.34.0",
4
4
  "description": "MemberJunction: Pinecone Implementation for AI Vectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,10 +15,10 @@
15
15
  "author": "MemberJunction.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@memberjunction/aiengine": "2.32.2",
19
- "@memberjunction/core": "2.32.2",
20
- "@memberjunction/global": "2.32.2",
21
- "@memberjunction/ai-vectors": "2.32.2",
18
+ "@memberjunction/aiengine": "2.34.0",
19
+ "@memberjunction/core": "2.34.0",
20
+ "@memberjunction/global": "2.34.0",
21
+ "@memberjunction/ai-vectors": "2.34.0",
22
22
  "@pinecone-database/pinecone": "2.2.2",
23
23
  "dotenv": "^16.4.1",
24
24
  "openai": "^4.28.4",