ollama / ollama-python

Ollama Python library
https://ollama.com
MIT License
2.69k stars 221 forks source link

Embeddings don't seem to work. #127

Closed luigi052005 closed 2 months ago

luigi052005 commented 2 months ago

I attempted to utilize the embedding model following the example provided on https://ollama.com/blog/embedding-models, yet each time, it returns: "Llamas are vegetarians and possess highly efficient digestive systems."

main.txt image

luigi052005 commented 2 months ago

Am i doing something wrong here?

chandansp27 commented 2 months ago

Hi, The issue is from the n_results parameter set to 1, Chroma retrieves docs using the query, but the constraint with RAG is that the retrieved document might not always be the most relevant one to the query. When n_results is set to 1, only the 'Llamas are vegetarians.... ' was retrieved which caused the incorrect answer.

Upon increasing the n_resuts to 2, this is the top docs retrieved:

{'ids': [['4', '5']], 'distances': [[177.4359130859375, 255.44308471679688]], 'metadatas': [[None, None]], 'embeddings': None, 'documents': [['Llamas are vegetarians and have very efficient digestive systems', 'Llamas live to be about 20 years old, though some only live for 15 years and others live to be 30 years old']], 'uris': None, 'data': None}

and this is the response:

"Based on the data provided, we can determine that llamas are vegetarians and have efficient digestive systems. This means that they are able to extract nutrients from their diet effectively and efficiently, which can contribute to their longevity. The average lifespan of a llama is around 15-20 years in captivity, with some individuals living up to 30 years or more. This is relatively long for an animal of its size, as many larger animals tend to have shorter lifespans due to their increased metabolic demands and higher risk of health problems."

There are many techniques to improve retrieval accuracy like changing the parameters like n_results to a higher number, hybrid retrievers like BM25, re-ranking the retrieved docs using the prompt, and many more.

luigi052005 commented 2 months ago

Thanks for the detailed explanation.