Skip to content
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

Modular RAG - Part 1 #1603

Closed
ThomasVitale opened this issue Oct 26, 2024 · 4 comments
Closed

Modular RAG - Part 1 #1603

ThomasVitale opened this issue Oct 26, 2024 · 4 comments
Labels
enhancement New feature or request epic RAG Issues related to Retrieval Augmented Generation

Comments

@ThomasVitale
Copy link
Contributor

ThomasVitale commented Oct 26, 2024

This issue will track the first part of the adoption of the Modular RAG architecture in Spring AI.

Context

The work can be split into two categories.

  1. The design and implementation of the building blocks for RAG modules that will be done in the org.springframework.ai.rag package. Each component is well encapsulated and can be used by itself to compose any kind of RAG flow. For example, you can use such components to build your own RAG flows using Spring State Machine, Spring Cloud Function or Spring Cloud Data Flow.
  2. Using the Advisor API, a RetrievalAugmentationAdvisor will be implemented to provide some out-of-the-box RAG flows using the building blocks defined in the previous category.

For background information, please refer to the following sources:

Design

Modules

In this first part, the focus will be on establishing the following modules and submodules:

This issue will be updated as we progress with the design and implementation work.

Advisor

In this first part, the focus will be on:

  • Establishing a RetrievalAugmentationAdvisor.
  • Adopting the available sub-modules to support Naive and Advanced RAG flows.
  • Experimental branching and conditional components.

Untitled-2024-10-24-1557

ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Oct 26, 2024
* Establish new package for Modular RAG components.
* Add new Query API, representing a query in the context of a RAG flow.
* Define Retrieval package for the RAG building blocks handling the data retrieval operations.
* Relocate DocumentRetriever to Retrieval package and implement VectorStoreDocumentRetriever.
* Introduce RetrievalAugmentationAdvisor as the successor of QuestionAnswerAdvisor. It uses the Retrieval building blocks described in the previous point.
* Make Advisor APIs null-safe and update tests accordingly.

Relates to gh-spring-projects#1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Oct 28, 2024
* Establish new package for Modular RAG components.
* Add new Query API, representing a query in the context of a RAG flow.
* Define Retrieval package for the RAG building blocks handling the data retrieval operations.
* Relocate DocumentRetriever to Retrieval package and implement VectorStoreDocumentRetriever.
* Introduce RetrievalAugmentationAdvisor as the successor of QuestionAnswerAdvisor. It uses the Retrieval building blocks described in the previous point.
* Make Advisor APIs null-safe and update tests accordingly.

Relates to gh-spring-projects#1603

Signed-off-by: Thomas Vitale <[email protected]>
@asaikali asaikali added enhancement New feature or request RAG Issues related to Retrieval Augmented Generation epic labels Oct 30, 2024
markpollack pushed a commit that referenced this issue Oct 31, 2024
* Establish new package for Modular RAG components.
* Add new Query API, representing a query in the context of a RAG flow.
* Define Retrieval package for the RAG building blocks handling the data retrieval operations.
* Relocate DocumentRetriever to Retrieval package and implement VectorStoreDocumentRetriever.
* Introduce RetrievalAugmentationAdvisor as the successor of QuestionAnswerAdvisor. It uses the Retrieval building blocks described in the previous point.
* Make Advisor APIs null-safe and update tests accordingly.

Relates to gh-#1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Oct 31, 2024
* Add new QueryAugmentor API, a component for augmenting a user query with contextual data.
* Implement ContextualQueryAugmentor that combines the content of each document and add it to the original user prompt, with support for the scenario where the context is empty.
* Extend RetrievalAugmentationAdvisor to use the new augmentation building block.
* Introduce utility to assist in validating arguments for prompt-related operations.

Relates to gh-spring-projects#1603

Signed-off-by: Thomas Vitale <[email protected]>
tzolov pushed a commit that referenced this issue Nov 3, 2024
* Add new QueryAugmentor API, a component for augmenting a user query with contextual data.
* Implement ContextualQueryAugmentor that combines the content of each document and add it to the original user prompt, with support for the scenario where the context is empty.
* Extend RetrievalAugmentationAdvisor to use the new augmentation building block.
* Introduce utility to assist in validating arguments for prompt-related operations.

Relates to gh-#1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 9, 2024
Pre-Retrieval
* Introduce Pre-Retrieval Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #spring-projectsgh-1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 10, 2024
Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #spring-projectsgh-1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 10, 2024
Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #spring-projectsgh-1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 13, 2024
Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #spring-projectsgh-1603

Signed-off-by: Thomas Vitale <[email protected]>
ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 13, 2024
Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #spring-projectsgh-1603

Signed-off-by: Thomas Vitale <[email protected]>
markpollack pushed a commit that referenced this issue Nov 13, 2024
Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Query Analysis
* Introduce Query Analysis Module
* Define QueryTransformer API and TranslationQueryTransformer implementation
* Define QueryExpander API and MultiQueryExpander implementation
* Support QueryTransformer in RetrievalAugmentationAdvisor (support for QueryExpander will be in the next PR together with the needed DocumentFuser API).

Improvements
* Refine Retrieval and Augmentation Modules for increased robustness
* Expand test coverage for both modules
* Define clone() method for ChatClient.Builder

Tests
* Introduce “spring-ai-integration-tests” for full-fledged integration tests
* Add integration tests for RAG modules
* Add integration tests for RAG advisor

Relates to #gh-1603

Signed-off-by: Thomas Vitale <[email protected]>
@LuizyHub
Copy link
Contributor

Hello @ThomasVitale

Thank you for opening this issue and providing detailed context about the Modular RAG architecture.

While exploring the current documentation, I noticed that QuestionAnswerAdvisor is still described as the advisor for RAG flows (e.g., in the Spring AI documentation). However, this issue outlines the creation of a new RetrievalAugmentationAdvisor and its integration with modular components.

Could you elaborate on the reasoning behind moving away from QuestionAnswerAdvisor? Is it primarily about achieving better modularity, or are there limitations in the existing implementation that the new approach aims to address?

Additionally, if I missed something in the issue description regarding the specific differences or advantages of the new advisor, I'd appreciate any clarification.

Thank you for your work on this!

ThomasVitale added a commit to ThomasVitale/spring-ai that referenced this issue Nov 19, 2024
Pre-Retrieval:
* Consolidated naming and documentation

Retrieval:
* Consolidated naming and documentation
* Introduced DocumentJoiner sub-module and CompositionDocumentJoiner operator

Post-Retrieval:
* Introduced main interfaces for sub-modules. Implementation waiting for missing features in Document APIs

Orchestration:
* Introduced QueryRouter sub-module and AllDocumentRetrieversQueryRouter operator

Generation:
* Consolidated naming and documentation

Advisor:
* Introduced BaseAdvisor to reduce boilerplate when implementing Advisors
* Extended RetrievalAugmentationAdvisor to include the new sub-modules

Relates to #spring-projectsgh-1603
markpollack pushed a commit that referenced this issue Nov 20, 2024
Pre-Retrieval:
* Consolidated naming and documentation

Retrieval:
* Consolidated naming and documentation
* Introduced DocumentJoiner sub-module and CompositionDocumentJoiner operator

Post-Retrieval:
* Introduced main interfaces for sub-modules. Implementation waiting for missing features in Document APIs

Orchestration:
* Introduced QueryRouter sub-module and AllDocumentRetrieversQueryRouter operator

Generation:
* Consolidated naming and documentation

Advisor:
* Introduced BaseAdvisor to reduce boilerplate when implementing Advisors
* Extended RetrievalAugmentationAdvisor to include the new sub-modules

Relates to #gh-1603
@ThomasVitale
Copy link
Contributor Author

ThomasVitale commented Nov 24, 2024

@LuizyHub thanks for the interest! The Modular RAG work is still in progress for now. Once it's ready, we will provide detailed documentation and guidance on how to use these new components, including information on how the QuestionAnswerAdvisor is different and the reasoning behind this new solution. Some initial part has been included in the M4 release and it's described here: https://spring.io/blog/2024/11/20/spring-ai-1-0-0-m4-released#advanced-and-modular-rag Please, notice that this is still in preview/experimental.

I have some examples here: https://github.com/ThomasVitale/llm-apps-java-spring-ai?tab=readme-ov-file#-retrieval-augmented-generation-rag If you give it a try, we would be happy to receive any feedback to improve the solution before reaching a final version for the GA release. Thank you!

@ThomasVitale
Copy link
Contributor Author

The scope in this part 1 has been included in the M4 release. Next steps will be covered in #1811, so I'm closing this issue.

@kevintsai1202
Copy link

Can the changes to Modular RAG be updated in the document? I couldn't find these changes or example code in the official documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request epic RAG Issues related to Retrieval Augmented Generation
Projects
None yet
Development

No branches or pull requests

4 participants