@memberjunction/ai-vectors 2.32.1 → 2.33.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 +207 -0
  2. package/package.json +7 -7
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # @memberjunction/ai-vectors
2
+
3
+ The MemberJunction AI Vectors Core package provides the foundational abstractions and base classes for working with vector embeddings, vector databases, and vector operations within the MemberJunction ecosystem.
4
+
5
+ ## Features
6
+
7
+ - **Core Interfaces**: Fundamental interface definitions for vector operations
8
+ - **Base Classes**: Base implementation patterns for vector-related functionality
9
+ - **Database Abstraction**: Interface for vector database operations
10
+ - **Embedding Abstraction**: Interface for text embedding generation
11
+ - **Entity Integration**: Seamless integration with MemberJunction entities
12
+ - **Pagination Support**: Efficiently retrieve and process large sets of records
13
+ - **Type Definitions**: Comprehensive TypeScript types for vector operations
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @memberjunction/ai-vectors
19
+ ```
20
+
21
+ ## Core Components
22
+
23
+ ### Interfaces
24
+
25
+ The package defines several key interfaces for vector operations:
26
+
27
+ #### IEmbedding
28
+
29
+ Interface for text embedding generation:
30
+
31
+ ```typescript
32
+ interface IEmbedding {
33
+ createEmbedding(text: string, options?: any): any;
34
+ createBatchEmbedding(text: string[], options?: any): any;
35
+ }
36
+ ```
37
+
38
+ #### IVectorDatabase
39
+
40
+ Interface for vector database management:
41
+
42
+ ```typescript
43
+ interface IVectorDatabase {
44
+ listIndexes(options?: any): any;
45
+ createIndex(options: any): any;
46
+ deleteIndex(indexID: any, options?: any): any;
47
+ editIndex(indexID: any, options?: any): any;
48
+ }
49
+ ```
50
+
51
+ #### IVectorIndex
52
+
53
+ Interface for vector index operations:
54
+
55
+ ```typescript
56
+ interface IVectorIndex {
57
+ createRecord(record: any, options?: any): any;
58
+ createRecords(records: any[], options?: any): any;
59
+ getRecord(recordID: any, options?: any): any;
60
+ getRecords(recordIDs: any[], options?: any): any;
61
+ updateRecord(record: any, options?: any): any;
62
+ updateRecords(records: any[], options?: any): any;
63
+ deleteRecord(recordID: any, options?: any): any;
64
+ deleteRecords(recordIDs: any[], options?: any): any;
65
+ }
66
+ ```
67
+
68
+ ### VectorBase Class
69
+
70
+ The `VectorBase` class serves as the foundation for vector operations, providing:
71
+
72
+ - Integration with MemberJunction's metadata system
73
+ - Entity record retrieval and manipulation
74
+ - Pagination support for handling large datasets
75
+ - Helper methods for AI model and vector database access
76
+
77
+ ## Usage
78
+
79
+ ### Extending the Base Class
80
+
81
+ Create specialized vector operation classes by extending `VectorBase`:
82
+
83
+ ```typescript
84
+ import { VectorBase } from '@memberjunction/ai-vectors';
85
+
86
+ export class MyVectorProcessor extends VectorBase {
87
+ async processEntityRecords(entityId: string): Promise<void> {
88
+ // Get entity records
89
+ const records = await this.GetRecordsByEntityID(entityId);
90
+
91
+ // Process each record
92
+ for (const record of records) {
93
+ // Your vector processing logic here
94
+ }
95
+ }
96
+
97
+ async paginatedProcess(entityId: string): Promise<void> {
98
+ // Process records page by page
99
+ const params = {
100
+ EntityID: entityId,
101
+ PageNumber: 1,
102
+ PageSize: 100,
103
+ ResultType: 'entity_object'
104
+ };
105
+
106
+ const records = await this.PageRecordsByEntityID(params);
107
+ // Process paged records
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### Implementing the Interfaces
113
+
114
+ Implement the interfaces to create specific provider implementations:
115
+
116
+ ```typescript
117
+ import { IEmbedding } from '@memberjunction/ai-vectors';
118
+
119
+ export class OpenAIEmbedding implements IEmbedding {
120
+ constructor(private apiKey: string) {}
121
+
122
+ async createEmbedding(text: string): Promise<number[]> {
123
+ // Implementation using OpenAI's embedding API
124
+ }
125
+
126
+ async createBatchEmbedding(texts: string[]): Promise<number[][]> {
127
+ // Batch implementation
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### Working with Entity Records
133
+
134
+ The package provides utilities for working with MemberJunction entities:
135
+
136
+ ```typescript
137
+ import { VectorBase, PageRecordsParams } from '@memberjunction/ai-vectors';
138
+
139
+ class EntityVectorizer extends VectorBase {
140
+ async vectorizeEntities(entityId: string): Promise<void> {
141
+ // Get AI model for embeddings
142
+ const embeddingModel = this.GetAIModel();
143
+
144
+ // Get vector database
145
+ const vectorDb = this.GetVectorDatabase();
146
+
147
+ // Process records in pages
148
+ let pageNumber = 1;
149
+ let hasMoreRecords = true;
150
+
151
+ while (hasMoreRecords) {
152
+ const params: PageRecordsParams = {
153
+ EntityID: entityId,
154
+ PageNumber: pageNumber,
155
+ PageSize: 50,
156
+ ResultType: 'entity_object'
157
+ };
158
+
159
+ const records = await this.PageRecordsByEntityID(params);
160
+ hasMoreRecords = records.length === params.PageSize;
161
+ pageNumber++;
162
+
163
+ // Process the current page of records
164
+ // ...
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ## Integration with MemberJunction
171
+
172
+ This package works in harmony with other MemberJunction packages:
173
+
174
+ ```typescript
175
+ import { VectorBase } from '@memberjunction/ai-vectors';
176
+ import { AIEngine } from '@memberjunction/aiengine';
177
+ import { Metadata, RunView } from '@memberjunction/core';
178
+
179
+ // Your vector processing will have access to:
180
+ // - Entity metadata
181
+ // - AI models configuration
182
+ // - Vector database configuration
183
+ // - User context
184
+ ```
185
+
186
+ ## Package Ecosystem
187
+
188
+ This core package serves as the foundation for a suite of vector-related packages:
189
+
190
+ - `@memberjunction/ai-vectors` - Core abstractions (this package)
191
+ - `@memberjunction/ai-vectordb` - Vector database interface
192
+ - `@memberjunction/ai-vectors-sync` - Entity synchronization with vector databases
193
+ - `@memberjunction/ai-vectors-pinecone` - Pinecone vector database implementation
194
+ - `@memberjunction/ai-vectors-dupe` - Duplicate detection using vector similarity
195
+
196
+ ## Dependencies
197
+
198
+ - `@memberjunction/core`: MemberJunction core library
199
+ - `@memberjunction/global`: MemberJunction global utilities
200
+ - `@memberjunction/core-entities`: MemberJunction entity definitions
201
+ - `@memberjunction/aiengine`: MemberJunction AI engine
202
+ - `@memberjunction/ai`: MemberJunction AI abstractions
203
+ - `@memberjunction/ai-vectordb`: Vector database interfaces
204
+
205
+ ## License
206
+
207
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-vectors",
3
- "version": "2.32.1",
3
+ "version": "2.33.0",
4
4
  "description": "MemberJunction: AI Vectors Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,12 +15,12 @@
15
15
  "author": "MemberJunction.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@memberjunction/core": "2.32.1",
19
- "@memberjunction/global": "2.32.1",
20
- "@memberjunction/core-entities": "2.32.1",
21
- "@memberjunction/aiengine": "2.32.1",
22
- "@memberjunction/ai": "2.32.1",
23
- "@memberjunction/ai-vectordb": "2.32.1",
18
+ "@memberjunction/core": "2.33.0",
19
+ "@memberjunction/global": "2.33.0",
20
+ "@memberjunction/core-entities": "2.33.0",
21
+ "@memberjunction/aiengine": "2.33.0",
22
+ "@memberjunction/ai": "2.33.0",
23
+ "@memberjunction/ai-vectordb": "2.33.0",
24
24
  "dotenv": "^16.4.1",
25
25
  "openai": "^4.28.4"
26
26
  },