spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.23k stars 822 forks source link

Results for SimilaritySearch in RAG Application with Ollama always return 0 documents #1625

Open cjullien opened 1 week ago

cjullien commented 1 week ago

Bug description When I create a RAG Application with SimilaritySearch, the search returns similar documents when using Azure OpenAI, but always returns zero documents with Ollama. The issue occurs specifically when I use the withSimilarityThreshold parameter with Ollama.

Environment last version of spring-ai BOM ollama with llama 3.2 Azure OpenAI PGVector

Steps to reproduce When I use withSimilarityThreshold with Ollama, I always have 0 Document in my similarDocuments (it's ok with Azure OpenAI)

   var similarity = 0.8; 
    var topk =20;
    var searchRequest = SearchRequest.query(question.question())
            .withTopK(topk)
            .withSimilarityThreshold(similarity);
     List<Document> similarDocuments = vectorStore.similaritySearch(searchRequest);

Expected behavior The search should return similar results between Azure OpenAI and Ollama. However, Ollama consistently returns zero similar documents.

Observed Behavior

Azure OpenAI: Returns a list of documents that meet the similarity threshold. Ollama: Returns zero documents, regardless of the similarity threshold set.

Additional Information

Configuration Consistency: The vectorStore configuration is identical for both platforms. Error Logs: No explicit error messages are thrown; however, the empty response from Ollama does not align with the expected output. [spring-ai-bootstraping] [nio-8080-exec-1] c.c.s.s.controller.AskRagController : Found 0 similar documents

asaikali commented 1 week ago

What embedding model are you using with ollama?

cjullien commented 1 week ago

I tested with the following models

spring.ai.ollama.embedding.options.model=nomic-embed-text

spring.ai.ollama.embedding.options.model=mxbai-embed-large

spring.ai.ollama.embedding.options.model=chroma/all-minilm-l6-v2-f32

spring.ai.ollama.embedding.options.model=hellord/e5-mistral-7b-instruct:Q4_0