@@ -39,17 +39,18 @@ export async function embedForSector(text: string, sector: string): Promise<numb
3939async function embedWithOpenAI ( text : string , sector : string ) : Promise < number [ ] > {
4040 if ( ! env . openai_key ) throw new Error ( 'OpenAI API key not configured' )
4141
42- const modelMap : Record < string , string > = {
42+ const defaultModelMap : Record < string , string > = {
4343 episodic : 'text-embedding-3-small' ,
4444 semantic : 'text-embedding-3-small' ,
4545 procedural : 'text-embedding-3-small' ,
4646 emotional : 'text-embedding-3-small' ,
4747 reflective : 'text-embedding-3-large'
4848 }
4949
50- const model = modelMap [ sector ] || 'text-embedding-3-small'
50+ const model = env . openai_model || defaultModelMap [ sector ] || 'text-embedding-3-small'
5151
52- const response = await fetch ( 'https://api.openai.com/v1/embeddings' , {
52+ const baseUrl = env . openai_base_url . replace ( / \/ $ / , '' )
53+ const response = await fetch ( `${ baseUrl } /embeddings` , {
5354 method : 'POST' ,
5455 headers : {
5556 'content-type' : 'application/json' ,
@@ -58,7 +59,7 @@ async function embedWithOpenAI(text: string, sector: string): Promise<number[]>
5859 body : JSON . stringify ( {
5960 input : text ,
6061 model,
61- dimensions : env . vec_dim <= 1536 ? env . vec_dim : undefined
62+ dimensions : env . vec_dim
6263 } )
6364 } )
6465
@@ -73,11 +74,12 @@ async function embedWithOpenAI(text: string, sector: string): Promise<number[]>
7374async function embedBatchOpenAI ( texts : Record < string , string > ) : Promise < Record < string , number [ ] > > {
7475 if ( ! env . openai_key ) throw new Error ( 'OpenAI API key not configured' )
7576
76- const model = 'text-embedding-3-small'
77+ const model = env . openai_model || 'text-embedding-3-small'
7778 const inputTexts = Object . values ( texts )
7879 const sectors = Object . keys ( texts )
7980
80- const response = await fetch ( 'https://api.openai.com/v1/embeddings' , {
81+ const baseUrl = env . openai_base_url . replace ( / \/ $ / , '' )
82+ const response = await fetch ( `${ baseUrl } /embeddings` , {
8183 method : 'POST' ,
8284 headers : {
8385 'content-type' : 'application/json' ,
@@ -86,7 +88,7 @@ async function embedBatchOpenAI(texts: Record<string, string>): Promise<Record<s
8688 body : JSON . stringify ( {
8789 input : inputTexts ,
8890 model,
89- dimensions : env . vec_dim <= 1536 ? env . vec_dim : undefined
91+ dimensions : env . vec_dim
9092 } )
9193 } )
9294
@@ -492,13 +494,15 @@ export function getEmbeddingInfo(): Record<string, any> {
492494 switch ( env . emb_kind ) {
493495 case 'openai' :
494496 info . configured = ! ! env . openai_key
497+ info . base_url = env . openai_base_url
498+ info . model_override = env . openai_model || null
495499 info . batch_api = env . embed_mode === 'simple'
496500 info . models = {
497- episodic : 'text-embedding-3-small' ,
498- semantic : 'text-embedding-3-small' ,
499- procedural : 'text-embedding-3-small' ,
500- emotional : 'text-embedding-3-small' ,
501- reflective : 'text-embedding-3-large'
501+ episodic : env . openai_model || 'text-embedding-3-small' ,
502+ semantic : env . openai_model || 'text-embedding-3-small' ,
503+ procedural : env . openai_model || 'text-embedding-3-small' ,
504+ emotional : env . openai_model || 'text-embedding-3-small' ,
505+ reflective : env . openai_model || 'text-embedding-3-large'
502506 }
503507 break
504508 case 'gemini' :
0 commit comments