UNPKG

better-qdrant-mcp-server

Version:

MCP server for enhanced Qdrant vector database functionality

44 lines 1.64 kB
import axios from 'axios'; import { BaseEmbeddingService } from './base.js'; export class OpenAIEmbeddingService extends BaseEmbeddingService { constructor(apiKey, endpoint, model) { super(apiKey, endpoint || 'https://api.openai.com/v1', model || 'text-embedding-ada-002'); // OpenAI's text-embedding-ada-002 produces 1536-dimensional embeddings this.vectorSize = 1536; this.defaultModel = 'text-embedding-ada-002'; this.defaultEndpoint = 'https://api.openai.com/v1'; this.validateConfig(); } async generateEmbeddings(texts) { const response = await axios.post(`${this.endpoint}/embeddings`, { input: texts, model: this.model || this.defaultModel, }, { headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json', }, }); if (!response.data.data || !Array.isArray(response.data.data)) { throw new Error('Invalid response from OpenAI API'); } return response.data.data.map((item) => { if (!item.embedding || !Array.isArray(item.embedding)) { throw new Error('Invalid embedding format in OpenAI response'); } return item.embedding; }); } requiresApiKey() { return true; } validateConfig() { if (!this.apiKey) { throw new Error('OpenAI API key is required'); } if (!this.endpoint) { throw new Error('OpenAI endpoint is required'); } } } //# sourceMappingURL=openai.js.map