I already got this running with the default openAI model. However it looks like that the embedding does not work, since the model can not access the information located in the textfile.
I See others are using a custom embedder configuration when they use a different model. I can’t find any information on how to embed the knowledge source together with ollama.
I think I found a solution. I need to do two things:
Configure the LLM with the pretty low temperature. Not sure why this is the reason, but I guess with higher temperature the model tends to be more creative on its own model.
Actually tell the agent in his configuration (goal) to make use of his local knowledge sources.
When setting the temperature to <=0.3 I get the expected response pretty stable.
Is this behaviour expected?
Further I would like to learn more about custom embedder. I found out that a did not need the embedder at all in my configuration. So when do I need a custom embedder and where do I find infos on how to configure it. I found the config I used my accident here in the form.
Hey Torsten! As you’ve experienced, lower temperature should be better on embedding/RAG related projects where we need the information correctly. Here’s the explanation of temperature from OpenAI’s documents:
“What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.”
Also here’s the link for it: https://platform.openai.com/docs/api-reference/chat/create#chat-create-temperature (Just scroll a bit to temperature if link doesn’t land you strictly on that)
-I’m also trying to better understand the embedding stuff so i won’t be able to say anything there, but good luck!
Since crewai uses chroma as application db to make knowledge available to the LLM I found Chroma Docs useful for a start. At least I was able to find the configuration there.
Hi,
Do you have a sample code on how you got the embedding working using ollama model?
I have a custom knowledge source that I have created in my application. On creating the crew, like this
crew = Crew(
agents=[json_analyst, summarizer_agent],
tasks=[ analysis_task, summary_task],
verbose=True,
knowledge_sources=[knowledge_source],
embedder={
“provider”: “ollama”,
“config”: {
“model”: “nomic-embed-text”
}
},
process=Process.sequential
)
the script fails while creating the embedding with the following error -
Failed to upsert documents: Expected Embedings to be non-empty list or numpy array, got in upsert.
Embedder allows you to use your choice of embedding models.
The default is OPENAI. Here’s an example for Ollama:
from crewai import Agent, Task, Crew, Process, LLM
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
# Create a knowledge source
content = "Users name is John. He is 30 years old and lives in San Francisco."
string_source = StringKnowledgeSource(content=content)
# Create an LLM with a temperature of 0 to ensure deterministic outputs
llm = LLM(
model="ollama/llama3.2:latest", # run !ollama list to see models you have
temperature=0,
api_key=""
)
# Create an agent with the knowledge store
agent = Agent(
role="About User",
goal="You know everything about the user.",
backstory="""You are a master at understanding people and their preferences.""",
verbose=True,
allow_delegation=False,
llm=llm,
)
task = Task(
description="Answer the following questions about the user: {question}",
expected_output="An answer to the question.",
agent=agent,
)
crew = Crew(
agents=[agent],
tasks=[task],
verbose=True,
process=Process.sequential,
knowledge_sources=[string_source],
embedder={
"provider": "ollama",
"config": {
"model": "nomic-embed-text",
"api_key": ""
}
}
)
result = crew.kickoff(inputs={"question": "What city does John live in and how old is he?"})
Also, setting the temperature=0 basically makes the model less creative and a bit more deterministic and vice versa.