-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rag Advanced example #7
Comments
@ogbozoyan thanks for your message! I'm currently working on a Modular RAG implementation in Spring AI. You can follow the status of the first stage of the implementation in this issue: spring-projects/spring-ai#1603. Soon, documentation will be available for all the new functionality introduced in that issue. It will be part of the upcoming M4 release of Spring AI. What you find in this repo in the advanced-rag example is actually part of what I was validating before delivering the changes to Spring AI. I started that for convenience, but soon I will move that research-based code elsewhere to avoid confusion, while still leaving the RAG-related examples here. |
@ThomasVitale thanks, Great news, I'll be looking forward |
@ThomasVitale, while using your implementation Advanced RAG facing with next problem:
I think this is because of private static final PromptTemplate DEFAULT_PROMPT_TEMPLATE = new PromptTemplate("""
Context information is below.
---------------------
{context}
---------------------
Given the context information and no prior knowledge, answer the query.
Follow these rules:
1. If the answer is not in the context, just say that you don't know.
2. Avoid statements like "Based on the context..." or "The provided information...".
Query: {query}
Answer:
"""); MY CONFIGS:
ChatClient configuration @Bean
fun ollamaClient(): ChatClient {
val documentRetriever: VectorStoreDocumentRetriever = VectorStoreDocumentRetriever.builder()
.vectorStore(vectorStore)
.similarityThreshold(0.50)
.topK(3)
.build()
return chatClientBuilder
.defaultAdvisors(
// MessageChatMemoryAdvisor(inMemoryChatMemory(), DEFAULT_CHAT_MEMORY_CONVERSATION_ID, 50),
VectorStoreChatMemoryAdvisor(vectorStore, DEFAULT_CHAT_MEMORY_CONVERSATION_ID, 5),
SimpleLoggerAdvisor(),
RetrievalAugmentationAdvisor.builder()
.documentRetriever(documentRetriever)
.order(Ordered.HIGHEST_PRECEDENCE)
.build()
)
.build()
} ai:
ollama:
base-url: ${OLLAMA_BASE_URL:http://localhost:11434/}
embedding:
options:
model: ${AI_OLLAMA_EMBEDDING_OPTIONS_MODEL:mxbai-embed-large:latest}
chat:
options:
model: ${OLLAMA_CHAT_MODEL:llama3.2:3b}
temperature: ${OLLAMA_CHAT_TEMPERATURE:0.6}
num-ctx: 16384
vectorstore:
pgvector:
initialize-schema: true
index-type: HNSW
distance-type: COSINE_DISTANCE
dimensions: 1024 |
If I understood correctly, you would like the model to answer based on its own knowledge in case the retrieval step returns no document? By default, if no documents are found in the retrieval step, the model is instructed not to answer in order to mitigate the risk of hallucinations. You can customize the ContextQueryAugmenter to allow an empty context and still ask the model to answer the question. You can find an example here: https://github.com/ThomasVitale/llm-apps-java-spring-ai/blob/main/rag/rag-sequential/rag-naive/src/main/java/com/thomasvitale/ai/spring/RagControllerEmptyContext.java#L27 |
You understood it right, but it seems to me problem in another advisor VectorStoreChatMemoryAdvisor(vectorStore, DEFAULT_CHAT_MEMORY_CONVERSATION_ID, 5), I've take a look what prompt goes to model and see a lot of trash cashed from VectorStoreChatMemory Did you test the RAG with memorization? |
Also i has some conversation in pull request spring-projects/spring-ai#1528 (comment) where saw example with usage self implemented |
You're implementation of RAG advisor look much better and more professional. Would you like to make a pull request and add it to the Spring AI project ?
And also i didn't quit understand, what's the purpose of those interfaces?
and an empty package
The text was updated successfully, but these errors were encountered: