-
Notifications
You must be signed in to change notification settings - Fork 50
Add websearch #86
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
Merged
Merged
Add websearch #86
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e5bdaf0
websearch pipeline
laetitia-wilhelm 75a8b3a
websearch - half pipeline - not tested
laetitia-wilhelm 22009aa
correct RAG import - LLM HS
laetitia-wilhelm cbb7c8c
extract new subqueries
laetitia-wilhelm 43eb8cd
query extraction solved
laetitia-wilhelm 7d0e86a
use_rag(true), use_summary(wrong): working
laetitia-wilhelm ed72368
local webrag working
laetitia-wilhelm ffdb4c9
clean folder
laetitia-wilhelm 87aa7fb
websearch function improved
laetitia-wilhelm 65c8dbc
API mode working + sources output update
laetitia-wilhelm d1c513d
config file API
laetitia-wilhelm 1ac8e07
sources correct - websearch unreliable
laetitia-wilhelm 381d6cc
clean + stop search function
laetitia-wilhelm 3cde125
websearch doc
laetitia-wilhelm 1a4b105
Merge branch 'master' of https://github.com/swiss-ai/mmore into webRag
laetitia-wilhelm 1a3175d
delete print
laetitia-wilhelm 7672f19
corrected import
laetitia-wilhelm 9e60558
corrected link
laetitia-wilhelm ede3fd0
Switch LangServe to LangGraph
laetitia-wilhelm c62ef31
ruff + isort check done
laetitia-wilhelm 8c99ece
ruff format
fabnemEPFL fb12473
changed import
laetitia-wilhelm 904cca8
formatting done
laetitia-wilhelm 46fc88d
Merge branch 'web_search' of https://github.com/laetitia-wilhelm/mmor…
laetitia-wilhelm 8d5376e
removed unused import
fabnemEPFL d6d802c
Simplified loading of configuration
fabnemEPFL 9800fe9
fixed some logic issues
fabnemEPFL cfcf101
renamed a method in websearchRAG/websearch.py
fabnemEPFL 2660792
fixed some typing / logic issues
fabnemEPFL 0094a23
updated slightly the documentation of websearch
fabnemEPFL f70d837
rotation of devices when loading several llms
fabnemEPFL f183178
removed useless newlines
fabnemEPFL e72efaf
ruff formatting
fabnemEPFL 1de7a57
bug fix
fabnemEPFL 2c7fcde
isort
fabnemEPFL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # WebSearch Integration in RAG Pipeline | ||
|
|
||
| ## Implementation | ||
|
|
||
| ### Overview | ||
| The WebSearch integration uses the DuckDuckGo search API through a wrapper provided by the LangChain library. The implementation combines: | ||
|
|
||
| - **DuckDuckGo Search:** Retrieves external information through concise subqueries generated by a LLm | ||
| - **LLM Integration:** Summarizes and integrates retrieved web snippets with RAG results to provide a final answer | ||
|
|
||
| ## Customization | ||
|
|
||
| Based on the implementation of the `RAG` module, the `Websearch` module enables the creation of a modular Websearch inference pipeline for your indexed multimodal documents, using two inference modes: | ||
| 1. **API**: Creates a server hosting the pipeline | ||
| 2. **Local**: Runs the inference locally | ||
|
|
||
| You can customize various parts of the pipeline by defining [an inference Websearch configuration file](/examples/websearchRAG/config_api.yaml). | ||
|
|
||
| Users can adjust the pipeline according to their [requirements](/examples/websearchRAG/config.yaml) through the following parameters: | ||
|
|
||
| - `use_rag`: Enables or disables RAG retrieval. | ||
| - `use_summary`: Activates summarization of retrieved web snippets. | ||
| - `n_loops`: Defines the number of search iterations to refine results. | ||
| - `n_subqueries`: Specifies the number of subqueries generated for each input query. | ||
|
|
||
| ### Workflow | ||
|
|
||
| 0. **RAG pipeline:** | ||
| - Launch the RAG pipeline if `use_rag` is enabled and the set the output as being the current knowledge | ||
| 1. **Input Query Processing:** | ||
| - The pipeline processes the user query and generates subqueries for web searches in order to complete the current knowledge. | ||
| 2. **WebSearch Execution:** | ||
| - DuckDuckGo searches are performed for each subquery | ||
| 3. **Summarization:** | ||
| - Retrieved web snippets are summarized using an LLM if `use_summary` is enabled. | ||
| 4. **Integration with RAG (if use_rag):** | ||
| - WebSearch results are combined with RAG outputs to generate the current knowledge | ||
| 5. **Start again:** | ||
| - We loop again from step 1 with the updated current knowledge | ||
|
|
||
| ## Minimal Example | ||
|
|
||
| Here is a example to create a Websearch pipeline hosted through [LangServe](https://python.langchain.com/docs/langserve/) servers. | ||
|
|
||
| 1. Create your RAG Inference config file based on the [local example](/examples/websearch/config.yaml) or the [API example](/examples/websearch/config_api.yaml). | ||
|
|
||
| 2. Start your Websearch pipeline using the `run_websearch.py` script and your config file | ||
| ```bash | ||
| python3 -m mmore websearch --config_file /path/to/config.yaml | ||
|
fabnemEPFL marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| 3. In API mode, query the server like any other LangServe server: | ||
| ```bash | ||
| curl --location --request POST http://localhost:8000/websearch/ \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d ' { | ||
| "query": { | ||
| "input": "When was Barack Obama born?", | ||
| "collection_name": "my_docs" | ||
| }, | ||
| "use_rag": true, | ||
| "use_summary": true | ||
| } | ||
| }' | ||
| ``` | ||
| In the API mode, it is necessary to provide the `use_rag` and `use_summary`parameters in the query, the number of `n_loops` and `n_subqueries` are defined in the config file. | ||
|
|
||
| In local mode, the pipeline is run directly with the input data specified in the configuration file and the result is saved at the specified path. | ||
|
|
||
| For both mode, if we want to use the RAG pipeline, it is necessay to provide the path to the rag configuration file. | ||
|
|
||
| ## Results and Outputs | ||
|
|
||
| ### Output Format | ||
| The pipeline provides outputs in the following structure: | ||
|
|
||
| - **Short Answer:** Concise response derived from combined RAG and WebSearch results. | ||
| - **Detailed Answer:** Expanded response with context from both sources. | ||
| - **Sources:** A list of URLs and their respective titles in the format: | ||
| ```json | ||
| {"URL": ["Title 1", "Title 2", ...]} | ||
| ``` | ||
|
|
||
| ### Example Output | ||
| ```json | ||
| { | ||
| "query": "What are the latest advancements in AI?", | ||
| "rag_informations": "Pre-existing knowledge from RAG.", | ||
| "rag_summary": "Summary of RAG knowledge.", | ||
| "web_summary": "Summarized web search information.", | ||
| "short_answer": "AI advancements include new models and real-time applications.", | ||
| "detailed_answer": "Recent AI developments include breakthroughs in large language models and innovative real-time applications, supported by diverse resources from RAG and web search.", | ||
| "sources": { | ||
| "https://example1.com" : ["AI Breakthrough; Latest in AI"], | ||
| "https://example2.com" : ["Advancements in AI; AI Trends"], | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| websearch: | ||
| use_rag: true | ||
| rag_config_path: examples/rag/config.yaml | ||
| use_summary: true | ||
| n_subqueries : 2 | ||
| input_file: examples/rag/output.json | ||
| input_queries: examples/rag/queries.jsonl | ||
| output_file: examples/websearchRAG/enhanced_results_trial.json | ||
| n_loops: 2 | ||
| max_searches: 5 | ||
| mode: local | ||
| llm_config: | ||
| llm_name: OpenMeditron/meditron3-8b | ||
| max_new_tokens: 1200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| websearch: | ||
| rag_config_path: examples/rag/config_api.yaml | ||
| n_subqueries : 3 | ||
| n_loops: 2 | ||
| max_searches: 10 | ||
| mode: api | ||
| llm_config: | ||
| llm_name: OpenMeditron/meditron3-8b | ||
| max_new_tokens: 1200 | ||
|
|
||
| # Mode Config | ||
| mode_args: | ||
| endpoint: '/rag' | ||
| port: 8000 | ||
| host: 'localhost' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.