Repository: Giskard-AI/giskard-oss
Issue: Custom embedding model is not being used by KnowledgeBase
Root cause: Configuration Error

Hello @henchaves 
I read the document and applied your recommendation but still get an error.
Do you have any other recommendations?

```py
import os
import giskard
import pandas as pd
import google.generativeai as genai
from giskard.llm.client.gemini import GeminiClient
from giskard.llm.embeddings.fastembed import try_get_fastembed_embeddings
from llama_index.core.node_parser import SentenceSplitter
from llama_index.readers.file import PyMuPDFReader
from giskard.rag import KnowledgeBase, generate_testset, QATestset

pd.set_option("display.max_colwidth", 400)
os.environ["API_KEY"] = "AIzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
genai.configure(api_key=os.environ["API_KEY"])
fe = try_get_fastembed_embeddings()
giskard.llm.embeddings.set_default_embedding(fe)
oc = GeminiClient(model="gemini-pro")
giskard.llm.set_default_client(oc)
print("Client successfully set.")

loader = PyMuPDFReader()
CVs_documents = loader.load(file_path="../KnowledgeBase/Walaa Akram Anwar.pdf")
print("pdf content is ", CVs_documents)
splitter = SentenceSplitter(chunk_size=512)
text_nodes = splitter(CVs_documents)
knowledge_base_df = pd.DataFrame([node.text for node in text_nodes], columns=["text"])
knowledge_base = KnowledgeBase(data=knowledge_base_df, llm_client=oc, embedding_model=fe)
testSet = generate_testset(knowledge_base, num_questions=6, agent_description="A chatbot answering questions about CVS")
print("generated Questions ", testSet)
QATestset.save(testSet,path="CVs_testSet.jsonl")
testSet.to_pandas().head(5)
```
the error appears is:
```
:\OracleAutomation\AIAutomation\RAGTesting\TestDataGenerationUsingGemini.py", line 26, in <module>
    knowledge_base = KnowledgeBase(data=knowledge_base_df, llm_client=oc, embedding_model=fe)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Walaa Akram\AppData\Local\Programs\Python\Python311\Lib\site-packages\giskard\rag\knowledge_base.py", line 139, in __init__
    self._embedding_model = embedding_model or get_default_embedding()
                                               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Walaa Akram\AppData\Local\Programs\Python\Python311\Lib\site-packages\giskard\llm\embeddings\__init__.py", line 19, in get_default_embedding
    _default_embedding = _default_embedding or try_get_openai_embeddings() or try_get_fastembed_embeddings()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Walaa Akram\AppData\Local\Programs\Python\Python311\Lib\site-packages\giskard\llm\embeddings\openai.py", line 68, in try_get_openai_embeddings
    client = OpenAI()
             ^^^^^^^^
  File "C:\Users\Walaa Akram\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_client.py", line 105, in __init__
    raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

Process finished with exit code 1
```

_Originally posted by @walaa-akram in https://github.com/Giskard-AI/giskard/issues/2045#issuecomment-2423426775_
            

Hello @walaa-akram,

I tried to reproduce the error you got, executing the same code as you, but I didn't get this error.
Analyzing the error log, it seems that the `KnowledgeBase` is trying to call `get_default_embedding()` instead of using the `embedding_model` that you passed. 

Could you check the content of `fe` before calling `knowledge_base = KnowledgeBase(data=knowledge_base_df, llm_client=oc, embedding_model=fe)`? It seems that `fe` is None due to an Import error, and then it tries to use OpenAI embedding model instead of FastEmbed model.

Hello @walaa-akram,
do you have any update on the issue? Did you manage to make it work?