@seizn/summer 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/README.md ADDED
@@ -0,0 +1,278 @@
1
+ # @seizn/summer
2
+
3
+ RAG Infrastructure SDK for AI Applications. Build production-ready retrieval-augmented generation systems with vector search, hybrid search, and answer generation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @seizn/summer
9
+ # or
10
+ yarn add @seizn/summer
11
+ # or
12
+ pnpm add @seizn/summer
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { SummerClient } from '@seizn/summer';
19
+
20
+ const summer = new SummerClient({
21
+ apiKey: process.env.SEIZN_API_KEY!,
22
+ });
23
+
24
+ // Create a collection
25
+ const collection = await summer.createCollection({
26
+ name: 'my-docs',
27
+ description: 'My document collection',
28
+ });
29
+
30
+ // Index documents
31
+ await summer.index({
32
+ collectionId: collection.id,
33
+ content: 'Your document content here...',
34
+ metadata: { source: 'my-app' },
35
+ });
36
+
37
+ // Search
38
+ const results = await summer.search({
39
+ collectionId: collection.id,
40
+ query: 'What is machine learning?',
41
+ mode: 'hybrid',
42
+ rerank: true,
43
+ });
44
+
45
+ // RAG query
46
+ const answer = await summer.ask(collection.id, 'Explain machine learning');
47
+ console.log(answer.answer);
48
+ ```
49
+
50
+ ## Features
51
+
52
+ - **Document Indexing**: Automatic chunking and embedding with configurable strategies
53
+ - **Hybrid Search**: Combine vector similarity and keyword search
54
+ - **Reranking**: Cross-encoder reranking for improved relevance
55
+ - **Federated Search**: Search across multiple collections and sources
56
+ - **RAG Query**: Generate answers with citations from your documents
57
+ - **Analytics**: Track search performance and usage
58
+
59
+ ## API Reference
60
+
61
+ ### Configuration
62
+
63
+ ```typescript
64
+ const summer = new SummerClient({
65
+ apiKey: 'szn_...', // Required: Your Seizn API key
66
+ baseUrl: 'https://seizn.com/api/summer', // Optional: API base URL
67
+ timeout: 60000, // Optional: Request timeout (ms)
68
+ retries: 3, // Optional: Max retry attempts
69
+ onError: (error) => {}, // Optional: Error callback
70
+ });
71
+ ```
72
+
73
+ ### Collection Management
74
+
75
+ ```typescript
76
+ // Create collection
77
+ const collection = await summer.createCollection({
78
+ name: 'my-collection',
79
+ description: 'Optional description',
80
+ embeddingModel: 'voyage-3', // or 'voyage-3-lite'
81
+ });
82
+
83
+ // List collections
84
+ const collections = await summer.listCollections();
85
+
86
+ // Get collection
87
+ const collection = await summer.getCollection('col_123');
88
+
89
+ // Delete collection
90
+ await summer.deleteCollection('col_123');
91
+
92
+ // Get statistics
93
+ const stats = await summer.getCollectionStats('col_123');
94
+ ```
95
+
96
+ ### Document Indexing
97
+
98
+ ```typescript
99
+ // Index single document
100
+ const result = await summer.index({
101
+ collectionId: 'col_123',
102
+ content: 'Document text...',
103
+ title: 'Document Title',
104
+ externalId: 'doc-001',
105
+ metadata: { source: 'api', category: 'tech' },
106
+ chunkingStrategy: 'semantic', // 'fixed' | 'semantic' | 'paragraph'
107
+ chunkSize: 512,
108
+ chunkOverlap: 50,
109
+ });
110
+
111
+ // Bulk index
112
+ const result = await summer.bulkIndex({
113
+ collectionId: 'col_123',
114
+ documents: [
115
+ { content: 'Doc 1...', title: 'Title 1' },
116
+ { content: 'Doc 2...', title: 'Title 2' },
117
+ ],
118
+ });
119
+
120
+ // Get document
121
+ const doc = await summer.getDocument('doc_123');
122
+
123
+ // Delete document
124
+ await summer.deleteDocument('doc_123');
125
+ ```
126
+
127
+ ### Search
128
+
129
+ ```typescript
130
+ // Full search options
131
+ const results = await summer.search({
132
+ collectionId: 'col_123',
133
+ query: 'machine learning applications',
134
+ topK: 10,
135
+ threshold: 0.7,
136
+ mode: 'hybrid', // 'vector' | 'keyword' | 'hybrid'
137
+ rerank: true,
138
+ rerankTopN: 5,
139
+ filter: { category: 'tech' },
140
+ includeMetadata: true,
141
+ });
142
+
143
+ // Quick search shorthand
144
+ const results = await summer.query('col_123', 'my query', {
145
+ topK: 10,
146
+ mode: 'hybrid',
147
+ rerank: true,
148
+ });
149
+
150
+ // Access results
151
+ results.results.forEach((r) => {
152
+ console.log(`${r.title}: ${r.similarity}`);
153
+ });
154
+
155
+ // Timings
156
+ console.log(`Search took ${results.timings.totalMs}ms`);
157
+ ```
158
+
159
+ ### Federated Search
160
+
161
+ ```typescript
162
+ const results = await summer.federatedSearch({
163
+ query: 'machine learning',
164
+ sources: ['col_123', 'col_456'], // Optional: specific sources
165
+ topK: 20,
166
+ mode: 'hybrid',
167
+ rerank: true,
168
+ dedupe: true,
169
+ });
170
+
171
+ // Source statistics
172
+ results.sourceStats.forEach((s) => {
173
+ console.log(`${s.sourceId}: ${s.resultsCount} results in ${s.latencyMs}ms`);
174
+ });
175
+ ```
176
+
177
+ ### RAG Query
178
+
179
+ ```typescript
180
+ // Full RAG options
181
+ const answer = await summer.rag({
182
+ collectionId: 'col_123',
183
+ query: 'What is machine learning?',
184
+ systemPrompt: 'You are a helpful assistant.',
185
+ contextLimit: 8000,
186
+ citationStyle: 'inline', // 'inline' | 'footnote' | 'none'
187
+ model: 'claude-sonnet', // 'claude-sonnet' | 'claude-haiku'
188
+ });
189
+
190
+ // Quick ask shorthand
191
+ const answer = await summer.ask('col_123', 'What is machine learning?');
192
+
193
+ // Access answer
194
+ console.log(answer.answer);
195
+
196
+ // Access citations
197
+ answer.citations.forEach((c) => {
198
+ console.log(`[${c.id}] ${c.title}: ${c.relevance}`);
199
+ });
200
+
201
+ // Usage stats
202
+ console.log(`Tokens: ${answer.usage.totalTokens}`);
203
+ ```
204
+
205
+ ### Utilities
206
+
207
+ ```typescript
208
+ // Generate embeddings
209
+ const embeddings = await summer.embed(['text 1', 'text 2']);
210
+
211
+ // Rerank results
212
+ const ranked = await summer.rerank('query', [
213
+ { id: '1', text: 'Document 1' },
214
+ { id: '2', text: 'Document 2' },
215
+ ], 5);
216
+ ```
217
+
218
+ ### Analytics
219
+
220
+ ```typescript
221
+ const analytics = await summer.getAnalytics('col_123', 'week');
222
+
223
+ console.log(`Total searches: ${analytics.totalSearches}`);
224
+ console.log(`Avg latency: ${analytics.averageLatencyMs}ms`);
225
+ console.log('Top queries:', analytics.topQueries);
226
+ ```
227
+
228
+ ## Error Handling
229
+
230
+ ```typescript
231
+ import { SummerClient, SummerError } from '@seizn/summer';
232
+
233
+ const summer = new SummerClient({
234
+ apiKey: 'szn_...',
235
+ onError: (error: SummerError) => {
236
+ console.error(`Error [${error.code}]: ${error.message}`);
237
+ },
238
+ });
239
+
240
+ try {
241
+ await summer.search({ collectionId: 'col_123', query: 'test' });
242
+ } catch (error) {
243
+ const err = error as SummerError;
244
+ if (err.code === 'RATE_LIMITED') {
245
+ // Handle rate limiting
246
+ } else if (err.code === 'NOT_FOUND') {
247
+ // Collection doesn't exist
248
+ }
249
+ }
250
+ ```
251
+
252
+ ## TypeScript Support
253
+
254
+ Full TypeScript support with exported types:
255
+
256
+ ```typescript
257
+ import type {
258
+ Collection,
259
+ Document,
260
+ SearchRequest,
261
+ SearchResponse,
262
+ SearchResult,
263
+ RAGQueryResponse,
264
+ Citation,
265
+ SummerClientConfig,
266
+ SummerError,
267
+ } from '@seizn/summer';
268
+ ```
269
+
270
+ ## License
271
+
272
+ MIT - see [LICENSE](LICENSE) for details.
273
+
274
+ ## Links
275
+
276
+ - [Documentation](https://docs.seizn.com/summer)
277
+ - [API Reference](https://docs.seizn.com/api-reference)
278
+ - [GitHub](https://github.com/iruhana/seizn)
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Seizn Summer SDK - External Client Types
3
+ *
4
+ * Type definitions for external applications to integrate with
5
+ * Seizn's Summer RAG infrastructure.
6
+ */
7
+ interface Collection {
8
+ id: string;
9
+ name: string;
10
+ description?: string;
11
+ documentCount: number;
12
+ embeddingDimensions: number;
13
+ createdAt: string;
14
+ updatedAt?: string;
15
+ }
16
+ interface CreateCollectionRequest {
17
+ name: string;
18
+ description?: string;
19
+ embeddingModel?: 'voyage-3' | 'voyage-3-lite';
20
+ }
21
+ interface CreateCollectionResponse {
22
+ success: boolean;
23
+ collection: Collection;
24
+ }
25
+ interface Document {
26
+ id: string;
27
+ collectionId: string;
28
+ externalId?: string;
29
+ title?: string;
30
+ content: string;
31
+ metadata: Record<string, unknown>;
32
+ chunkCount: number;
33
+ createdAt: string;
34
+ updatedAt?: string;
35
+ }
36
+ interface IndexDocumentRequest {
37
+ collectionId: string;
38
+ externalId?: string;
39
+ title?: string;
40
+ content: string;
41
+ metadata?: Record<string, unknown>;
42
+ chunkingStrategy?: 'fixed' | 'semantic' | 'paragraph';
43
+ chunkSize?: number;
44
+ chunkOverlap?: number;
45
+ }
46
+ interface IndexDocumentResponse {
47
+ success: boolean;
48
+ document: Document;
49
+ chunksCreated: number;
50
+ }
51
+ interface BulkIndexRequest {
52
+ collectionId: string;
53
+ documents: Array<{
54
+ externalId?: string;
55
+ title?: string;
56
+ content: string;
57
+ metadata?: Record<string, unknown>;
58
+ }>;
59
+ chunkingStrategy?: 'fixed' | 'semantic' | 'paragraph';
60
+ }
61
+ interface BulkIndexResponse {
62
+ success: boolean;
63
+ indexed: number;
64
+ failed: number;
65
+ errors?: Array<{
66
+ index: number;
67
+ error: string;
68
+ }>;
69
+ }
70
+ type SearchMode = 'vector' | 'keyword' | 'hybrid';
71
+ interface SearchRequest {
72
+ collectionId: string;
73
+ query: string;
74
+ topK?: number;
75
+ threshold?: number;
76
+ mode?: SearchMode;
77
+ rerank?: boolean;
78
+ rerankTopN?: number;
79
+ filter?: Record<string, unknown>;
80
+ includeMetadata?: boolean;
81
+ }
82
+ interface SearchResult {
83
+ chunkId: string;
84
+ documentId: string;
85
+ externalId?: string;
86
+ title?: string;
87
+ content: string;
88
+ similarity: number;
89
+ rerankScore?: number;
90
+ metadata?: Record<string, unknown>;
91
+ }
92
+ interface SearchResponse {
93
+ success: boolean;
94
+ results: SearchResult[];
95
+ count: number;
96
+ mode: SearchMode;
97
+ timings: {
98
+ embedMs: number;
99
+ searchMs: number;
100
+ rerankMs?: number;
101
+ totalMs: number;
102
+ };
103
+ }
104
+ interface FederatedSource {
105
+ id: string;
106
+ name: string;
107
+ type: 'http' | 'agent';
108
+ priority: number;
109
+ weight: number;
110
+ }
111
+ interface FederatedSearchRequest {
112
+ query: string;
113
+ sources?: string[];
114
+ topK?: number;
115
+ mode?: SearchMode;
116
+ rerank?: boolean;
117
+ dedupe?: boolean;
118
+ }
119
+ interface FederatedSearchResponse {
120
+ success: boolean;
121
+ results: Array<SearchResult & {
122
+ source: string;
123
+ }>;
124
+ sourceStats: Array<{
125
+ sourceId: string;
126
+ resultsCount: number;
127
+ latencyMs: number;
128
+ }>;
129
+ timings: {
130
+ totalMs: number;
131
+ };
132
+ }
133
+ interface RAGQueryRequest {
134
+ collectionId: string;
135
+ query: string;
136
+ systemPrompt?: string;
137
+ contextLimit?: number;
138
+ citationStyle?: 'inline' | 'footnote' | 'none';
139
+ model?: 'claude-sonnet' | 'claude-haiku';
140
+ stream?: boolean;
141
+ }
142
+ interface Citation {
143
+ id: string;
144
+ documentId: string;
145
+ title?: string;
146
+ content: string;
147
+ relevance: number;
148
+ }
149
+ interface RAGQueryResponse {
150
+ success: boolean;
151
+ answer: string;
152
+ citations: Citation[];
153
+ usage: {
154
+ contextTokens: number;
155
+ responseTokens: number;
156
+ totalTokens: number;
157
+ };
158
+ timings: {
159
+ searchMs: number;
160
+ generationMs: number;
161
+ totalMs: number;
162
+ };
163
+ }
164
+ interface SummerClientConfig {
165
+ apiKey: string;
166
+ baseUrl?: string;
167
+ timeout?: number;
168
+ retries?: number;
169
+ onError?: (error: SummerError) => void;
170
+ }
171
+ interface SummerError {
172
+ code: string;
173
+ message: string;
174
+ status?: number;
175
+ details?: Record<string, unknown>;
176
+ }
177
+ interface CollectionStats {
178
+ collectionId: string;
179
+ documentCount: number;
180
+ chunkCount: number;
181
+ totalTokens: number;
182
+ storageBytes: number;
183
+ lastIndexedAt?: string;
184
+ }
185
+ interface SearchAnalytics {
186
+ period: 'day' | 'week' | 'month';
187
+ totalSearches: number;
188
+ averageLatencyMs: number;
189
+ topQueries: Array<{
190
+ query: string;
191
+ count: number;
192
+ }>;
193
+ modeDistribution: Record<SearchMode, number>;
194
+ }
195
+
196
+ /**
197
+ * Seizn Summer SDK Client
198
+ *
199
+ * TypeScript SDK for Seizn's Summer RAG infrastructure.
200
+ * Enables external applications to integrate with Seizn's
201
+ * vector search and RAG capabilities.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * import { SummerClient } from '@seizn/summer';
206
+ *
207
+ * const summer = new SummerClient({
208
+ * apiKey: process.env.SEIZN_API_KEY!,
209
+ * });
210
+ *
211
+ * // Index a document
212
+ * await summer.index({
213
+ * collectionId: 'my-collection',
214
+ * content: 'Document content...',
215
+ * metadata: { source: 'my-app' },
216
+ * });
217
+ *
218
+ * // Search
219
+ * const results = await summer.search({
220
+ * collectionId: 'my-collection',
221
+ * query: 'What is machine learning?',
222
+ * mode: 'hybrid',
223
+ * rerank: true,
224
+ * });
225
+ * ```
226
+ */
227
+
228
+ declare class SummerClient {
229
+ private readonly apiKey;
230
+ private readonly baseUrl;
231
+ private readonly timeout;
232
+ private readonly retries;
233
+ private readonly onError?;
234
+ constructor(config: SummerClientConfig);
235
+ /**
236
+ * Create a new collection
237
+ */
238
+ createCollection(request: CreateCollectionRequest): Promise<Collection>;
239
+ /**
240
+ * List all collections
241
+ */
242
+ listCollections(): Promise<Collection[]>;
243
+ /**
244
+ * Get collection by ID
245
+ */
246
+ getCollection(collectionId: string): Promise<Collection>;
247
+ /**
248
+ * Delete a collection
249
+ */
250
+ deleteCollection(collectionId: string): Promise<void>;
251
+ /**
252
+ * Get collection statistics
253
+ */
254
+ getCollectionStats(collectionId: string): Promise<CollectionStats>;
255
+ /**
256
+ * Index a single document
257
+ */
258
+ index(request: IndexDocumentRequest): Promise<IndexDocumentResponse>;
259
+ /**
260
+ * Bulk index multiple documents
261
+ */
262
+ bulkIndex(request: BulkIndexRequest): Promise<BulkIndexResponse>;
263
+ /**
264
+ * Get document by ID
265
+ */
266
+ getDocument(documentId: string): Promise<Document>;
267
+ /**
268
+ * Delete a document
269
+ */
270
+ deleteDocument(documentId: string): Promise<void>;
271
+ /**
272
+ * Update document metadata
273
+ */
274
+ updateDocumentMetadata(documentId: string, metadata: Record<string, unknown>): Promise<Document>;
275
+ /**
276
+ * Search within a collection
277
+ */
278
+ search(request: SearchRequest): Promise<SearchResponse>;
279
+ /**
280
+ * Quick search shorthand
281
+ */
282
+ query(collectionId: string, query: string, options?: {
283
+ topK?: number;
284
+ mode?: 'vector' | 'keyword' | 'hybrid';
285
+ rerank?: boolean;
286
+ }): Promise<SearchResponse>;
287
+ /**
288
+ * Federated search across multiple sources
289
+ */
290
+ federatedSearch(request: FederatedSearchRequest): Promise<FederatedSearchResponse>;
291
+ /**
292
+ * RAG query with answer generation
293
+ */
294
+ rag(request: RAGQueryRequest): Promise<RAGQueryResponse>;
295
+ /**
296
+ * Quick RAG query shorthand
297
+ */
298
+ ask(collectionId: string, question: string, options?: {
299
+ systemPrompt?: string;
300
+ contextLimit?: number;
301
+ }): Promise<RAGQueryResponse>;
302
+ /**
303
+ * Get search analytics
304
+ */
305
+ getAnalytics(collectionId: string, period?: 'day' | 'week' | 'month'): Promise<SearchAnalytics>;
306
+ /**
307
+ * Generate embedding for text (for external use)
308
+ */
309
+ embed(text: string | string[]): Promise<number[][]>;
310
+ /**
311
+ * Rerank results
312
+ */
313
+ rerank(query: string, documents: Array<{
314
+ id: string;
315
+ text: string;
316
+ }>, topN?: number): Promise<Array<{
317
+ id: string;
318
+ score: number;
319
+ }>>;
320
+ private request;
321
+ }
322
+ /**
323
+ * Create a Summer client instance
324
+ */
325
+ declare function createSummerClient(config: SummerClientConfig): SummerClient;
326
+
327
+ export { type BulkIndexRequest, type BulkIndexResponse, type Citation, type Collection, type CollectionStats, type CreateCollectionRequest, type CreateCollectionResponse, type Document, type FederatedSearchRequest, type FederatedSearchResponse, type FederatedSource, type IndexDocumentRequest, type IndexDocumentResponse, type RAGQueryRequest, type RAGQueryResponse, type SearchAnalytics, type SearchMode, type SearchRequest, type SearchResponse, type SearchResult, SummerClient, type SummerClientConfig, type SummerError, createSummerClient };