LlamaIndexTS: `VectorStoreIndex.init` broken when not using env variables
getEmbeddedModel initialises OpenAIEmbedding without any options passed to it when using:
let vsi = await VectorStoreIndex.init({
serviceContext: ...,
nodes: ...,
});
Trace:
Error: Set OpenAI Key in OPENAI_API_KEY env variable
at new OpenAISession (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/llm/openai.js:416:19)
at getOpenAISession (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/llm/openai.js:442:19)
at new OpenAIEmbedding (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/embeddings/OpenAIEmbedding.js:71:109)
at getEmbeddedModel (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/internal/settings/EmbedModel.js:15:31)
at new VectorStoreBase (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/storage/vectorStore/types.js:22:123)
at new SimpleVectorStore (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/storage/vectorStore/SimpleVectorStore.js:29:9)
at storageContextFromDefaults (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/storage/StorageContext.js:25:100)
at VectorStoreIndex.init (webpack-internal:///(rsc)/../LlamaIndexTS/packages/core/dist/indices/vectorStore/index.js:417
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 16 (11 by maintainers)
https://github.com/run-llama/LlamaIndexTS/pull/1798
yes, that’s a bug, i’ll send a PR
@parhammmm sorry for taking so long to look at this!
The problem is that VectorStoreIndex requires a vector store and a vector store requires an embedding model which defaults to
Settings.embedModel, so calling:will use the OpenAI embedding model which is the default value of
Settings.embedModel. So either you specify a vector store with embedding model or you change theSettings.embedModelvalue.I think we should remove this OpenAI default, see https://github.com/run-llama/LlamaIndexTS/issues/1797
I’ll close this ticket for now. Please feel free to reopen if that doesn’t work for you.
if so, would u please add a test case for this? I want to make repo stable
I was checking code of getEmbeddibgModel and now we do not use OpenAI directly there
I see, I think we didn’t pass some context properly, I will check that later
Same issue exists with
ChatMemoryBufferinSimpleChatEnginebecause ChatMemoryBuffer has it’s own llm context instead of using SimpleChatEngine’shttps://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts#L25
and
https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts#L39
and
https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/src/engines/chat/ContextChatEngine.ts#L53
@marcusschiesser no problem and thanks for replying!
Above would be the full example. If you just do that without setting
OPENAI_API_KEYit can be replicated.Our workaround was to provide the storage context.
serviceContextForEmbeddingjust returns a service context object with our embedding and llmSide note: I know the project now includes
Settingsetc but that would not work at all for our use case, hence the above. Please don’t deprecateserviceContextFromDefaultsit is very useful becauseSettingsis global from what I understand which is not usable for us.