Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e5bdaf0
websearch pipeline
laetitia-wilhelm May 20, 2025
75a8b3a
websearch - half pipeline - not tested
laetitia-wilhelm Jun 5, 2025
22009aa
correct RAG import - LLM HS
laetitia-wilhelm Jun 9, 2025
cbb7c8c
extract new subqueries
laetitia-wilhelm Jun 10, 2025
43eb8cd
query extraction solved
laetitia-wilhelm Jun 11, 2025
7d0e86a
use_rag(true), use_summary(wrong): working
laetitia-wilhelm Jun 14, 2025
ed72368
local webrag working
laetitia-wilhelm Jun 15, 2025
ffdb4c9
clean folder
laetitia-wilhelm Jun 17, 2025
87aa7fb
websearch function improved
laetitia-wilhelm Jun 19, 2025
65c8dbc
API mode working + sources output update
laetitia-wilhelm Jun 22, 2025
d1c513d
config file API
laetitia-wilhelm Jun 23, 2025
1ac8e07
sources correct - websearch unreliable
laetitia-wilhelm Jun 23, 2025
381d6cc
clean + stop search function
laetitia-wilhelm Jun 30, 2025
3cde125
websearch doc
laetitia-wilhelm Jun 30, 2025
1a4b105
Merge branch 'master' of https://github.com/swiss-ai/mmore into webRag
laetitia-wilhelm Jun 30, 2025
1a3175d
delete print
laetitia-wilhelm Jun 30, 2025
7672f19
corrected import
laetitia-wilhelm Jun 30, 2025
9e60558
corrected link
laetitia-wilhelm Jul 4, 2025
ede3fd0
Switch LangServe to LangGraph
laetitia-wilhelm Jul 13, 2025
c62ef31
ruff + isort check done
laetitia-wilhelm Jul 14, 2025
8c99ece
ruff format
fabnemEPFL Aug 4, 2025
fb12473
changed import
laetitia-wilhelm Aug 9, 2025
904cca8
formatting done
laetitia-wilhelm Aug 9, 2025
46fc88d
Merge branch 'web_search' of https://github.com/laetitia-wilhelm/mmor…
laetitia-wilhelm Aug 9, 2025
8d5376e
removed unused import
fabnemEPFL Aug 12, 2025
d6d802c
Simplified loading of configuration
fabnemEPFL Aug 13, 2025
9800fe9
fixed some logic issues
fabnemEPFL Aug 14, 2025
cfcf101
renamed a method in websearchRAG/websearch.py
fabnemEPFL Aug 15, 2025
2660792
fixed some typing / logic issues
fabnemEPFL Aug 15, 2025
0094a23
updated slightly the documentation of websearch
fabnemEPFL Sep 2, 2025
f70d837
rotation of devices when loading several llms
fabnemEPFL Sep 4, 2025
f183178
removed useless newlines
fabnemEPFL Sep 4, 2025
e72efaf
ruff formatting
fabnemEPFL Sep 4, 2025
1de7a57
bug fix
fabnemEPFL Sep 4, 2025
2c7fcde
isort
fabnemEPFL Sep 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions docs/websearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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
Comment thread
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:
```
URL: https://example.com, Title {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"],
}
}

14 changes: 14 additions & 0 deletions examples/websearchRAG/config.yaml
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
15 changes: 15 additions & 0 deletions examples/websearchRAG/config_api.yaml
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'
Loading