Project Files
src / embeddings / embed.ts
export async function embed(text: string): Promise<number[]> {
try {
// Point directly to LM Studio's native local server port
const response = await fetch("http://localhost:1234/v1/embeddings", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
input: text,
model: "text-embedding-nomic-embed-text-v1.5" // Match the exact model loaded in your LMS
})
});
if (!response.ok) throw new Error(`LMS API Error: ${response.status}`);
const data = await response.json();
return data.data[0].embedding;
} catch (error) {
console.error("Embedding fallback:", error);
return new Array(384).fill(0); // Standard safe zero-vector fallback
}
}