UNPKG

@gravityai-dev/pinecone

Version:

Pinecone vector database nodes for GravityWorkflow - knowledge management and vector operations

102 lines 3.7 kB
"use strict"; /** * Pinecone Upload Service * Handles vector upload operations with chunking support */ Object.defineProperty(exports, "__esModule", { value: true }); exports.executeUpload = executeUpload; const platform_1 = require("../../shared/platform"); const pineconeClient_1 = require("../../shared/pineconeClient"); const logger = (0, platform_1.createLogger)("PineconeUploadService"); /** * Sanitize metadata to ensure all values are valid for Pinecone * Converts null/undefined to empty strings */ function sanitizeMetadata(metadata) { if (!metadata) return {}; const sanitized = {}; for (const [key, value] of Object.entries(metadata)) { if (value === null || value === undefined) { sanitized[key] = ""; } else if (typeof value === "object" && !Array.isArray(value)) { // Recursively sanitize nested objects sanitized[key] = sanitizeMetadata(value); } else { sanitized[key] = value; } } return sanitized; } /** * Execute Pinecone upload */ async function executeUpload(config) { const namespace = config.namespace || "default"; try { logger.info("Starting Pinecone vector upload", { vectorId: config.vectorId, textLength: config.text.length, namespace, }); // Build credential context const credentialContext = { workflowId: config.context.workflow?.id || "unknown", executionId: config.context.executionId || "unknown", nodeId: config.context.nodeId, nodeType: "PineconeUpload", credentials: config.context.credentials || {}, }; // Initialize Pinecone client const pinecone = await (0, pineconeClient_1.initializePineconeClient)(credentialContext); const index = pinecone.index(config.indexName); // Sanitize metadata to ensure no null values const sanitizedMetadata = sanitizeMetadata(config.metadata); // For now, return a simple mock response // TODO: Implement actual upload logic with embedding generation const vectorCount = 1; logger.info("Successfully uploaded vector(s) to Pinecone", { vectorId: config.vectorId, namespace, vectorCount, }); // Extract URL and title from metadata if available const url = config.metadata?.url; const title = config.metadata?.title; // Build service result const serviceResult = { success: true, vectorId: config.vectorId, namespace, timestamp: new Date().toISOString(), vectorCount, summary: { url, title, totalTextLength: config.text.length, chunkingEnabled: config.enableChunking || false, chunkingStrategy: config.enableChunking ? config.chunkingStrategy : undefined, }, uploadedVectors: [ { id: config.vectorId, textLength: config.text.length, preview: config.text.substring(0, 100) + (config.text.length > 100 ? "..." : ""), }, ], }; return serviceResult; } catch (error) { logger.error("Failed to upload vector to Pinecone", { error: error.message, indexName: config.indexName, namespace, vectorId: config.vectorId, }); throw new Error(`Pinecone upload failed: ${error.message}`); } } //# sourceMappingURL=uploadService.js.map