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

[FEATURE] Return retrieved Contents/TextSegments when using AI Service with RAG #1015

Merged

Conversation

KaisNeffati
Copy link
Contributor

@KaisNeffati KaisNeffati commented Apr 24, 2024

Context

#660

Change

If you wish to access the sources (retrieved Contents used to augment the message),
you can easily do so now by wrapping the return type in the Result class:

interface Assistant {

    Result<String> chat(String userMessage);
}

Result<String> result = assistant.chat("How to do Easy RAG with LangChain4j?");

String answer = result.content();
List<Content> sources = result.sources();

Checklist

Before submitting this PR, please check the following points:

  • I have added unit and integration tests for my change
  • All unit and integration tests in the module I have added/changed are green
  • All unit and integration tests in the core and main modules are green
  • I have added/updated the documentation
  • I have added an example in the examples repo (only for "big" features)
  • I have added my new module in the BOM (only when a new module is added)

Checklist for adding new embedding store integration

  • I have added a {NameOfIntegration}EmbeddingStoreIT that extends from either EmbeddingStoreIT or EmbeddingStoreWithFilteringIT

@KaisNeffati KaisNeffati changed the title [FEATURE] Retrieve Documents when using AiService or ConversationalRe… [FEATURE] Retrieve Documents when using AiService Apr 25, 2024
@langchain4j langchain4j added P1 Highest priority P2 High priority labels Apr 29, 2024
Copy link
Owner

@langchain4j langchain4j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KaisNeffati thank you a lot for your contribution!

@KaisNeffati KaisNeffati force-pushed the feature/augmented_user_message branch from 951bc77 to 7cfac82 Compare May 6, 2024 12:07
@KaisNeffati KaisNeffati force-pushed the feature/augmented_user_message branch from 7cfac82 to 2d16e44 Compare May 6, 2024 12:13
@langchain4j
Copy link
Owner

Hi @KaisNeffati, do you mind if I will do and push some changes?

@KaisNeffati
Copy link
Contributor Author

KaisNeffati commented May 9, 2024

Feel free to do it @langchain4j

@langchain4j
Copy link
Owner

@KaisNeffati could you please add me as collaborator to your repo? I can't push to this branch/PR :(

@KaisNeffati
Copy link
Contributor Author

Done

- WithSources<T> -> Result<T>
- AugmentationRequest, AugmentationResult, RetrievalAugmentor and ContentInjector to use ChatMessage instead of UserMessage
- WithSources<T> -> Result<T>
- AugmentationRequest, AugmentationResult, RetrievalAugmentor and ContentInjector to use ChatMessage instead of UserMessage
- WithSources<T> -> Result<T>
- AugmentationRequest, AugmentationResult, RetrievalAugmentor and ContentInjector to use ChatMessage instead of UserMessage
@langchain4j
Copy link
Owner

@KaisNeffati thank you! I have pushed my changes, could you please review? I hope now it is a bit more generic (Result instead of WithSources). I have also changed UserMessage to ChatMessage right away in all places to avoid doing breaking changes one more time in the near future.

Copy link
Contributor Author

@KaisNeffati KaisNeffati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment below !

And Yeah, Result is a very wise choice. It confirms what I had in mind initially when I thought about 'ResponsePrompt' or 'ResponseMessage'. I'm glad to hear that you've found the right name 👏

Atherwise , all is good for me

- WithSources<T> -> Result<T>
- AugmentationRequest, AugmentationResult, RetrievalAugmentor and ContentInjector to use ChatMessage instead of UserMessage
@langchain4j
Copy link
Owner

@KaisNeffati thanks! Then I am merging it.

@langchain4j langchain4j merged commit d365ca4 into langchain4j:main May 17, 2024
6 checks passed
@langchain4j langchain4j changed the title [FEATURE] Retrieve Documents when using AiService [FEATURE] Return retrieved Contents/TextSegments when using AI Service with RAG May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Highest priority P2 High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants