@stackmemoryai/stackmemory
Version:
Lossless, project-scoped memory for AI coding tools. Durable context across sessions with 56 MCP tools, FTS5 search, conductor orchestrator, loop/watch monitoring, snapshot capture, pre-flight overlap checks, Claude/Codex/OpenCode wrappers, Linear sync, a
44 lines (43 loc) • 1.35 kB
JavaScript
import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
class OpenAIEmbeddingProvider {
dimension;
apiKey;
model;
constructor(apiKey, model, dimension) {
this.apiKey = apiKey;
this.model = model;
this.dimension = dimension;
}
async embed(text) {
const res = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`
},
body: JSON.stringify({ model: this.model, input: text })
});
if (!res.ok) throw new Error(`OpenAI embed failed: ${res.status}`);
const data = await res.json();
return data.data[0].embedding;
}
async embedBatch(texts) {
const res = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`
},
body: JSON.stringify({ model: this.model, input: texts })
});
if (!res.ok) throw new Error(`OpenAI embed batch failed: ${res.status}`);
const data = await res.json();
return data.data.map((d) => d.embedding);
}
}
export {
OpenAIEmbeddingProvider
};