~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
upaded readme
LearningCircuit18a21481c83d
diff --git a/README.md b/README.mdindex b17a085bed..74f1b738da 100644--- a/README.md+++ b/README.md@@ -2,6 +2,32 @@A powerful AI-powered research assistant that performs deep, iterative analysis using multiple LLMs and web searches. The system can be run locally for privacy or configured to use cloud-based LLMs for enhanced capabilities.+## Quick Start++```bash+# Install the package+pip install local-deep-research++# Install required browser automation tools+playwright install++# For local models, install Ollama+# Download from https://ollama.ai and then pull a model+ollama pull gemma3:12b+```++Then run:++```bash+# Start the web interface (recommended)+ldr-web # (OR python -m local_deep_research.web.app)++# OR run the command line version+ldr # (OR python -m local_deep_research.main)+```++Access the web interface at `http://127.0.0.1:5000` in your browser.+## Features- 🔍 **Advanced Research Capabilities**@@ -28,218 +54,172 @@ A powerful AI-powered research assistant that performs deep, iterative analysis- Transparent data handling- 🌐 **Enhanced Search Integration**- - **Auto-selection of search sources**: The "auto" search engine intelligently analyzes your query and selects the most appropriate search engine based on the query content- - **SearXNG** integration for local web-search engine, great for privacy, no API key required (requires a searxng server)- - Wikipedia integration for factual knowledge- - arXiv integration for scientific papers and academic research- - PubMed integration for biomedical literature and medical research- - DuckDuckGo integration for web searches (may experience rate limiting)- - SerpAPI integration for Google search results (requires API key)- - Google Programmable Search Engine integration for custom search experiences (requires API key)- - The Guardian integration for news articles and journalism (requires API key)+ - **Auto-selection of search sources**: The "auto" search engine intelligently analyzes your query and selects the most appropriate search engine+ - Multiple search engines including Wikipedia, arXiv, PubMed, Semantic Scholar, and more- **Local RAG search for private documents** - search your own documents with vector embeddings- - Full webpage content retrieval- - Source filtering and validation- - Configurable search parameters+ - Full webpage content retrieval and intelligent filtering-- 📑 **Local Document Search (RAG)**- - Vector embedding-based search of your local documents- - Create custom document collections for different topics- - Privacy-preserving - your documents stay on your machine- - Intelligent chunking and retrieval- - Compatible with various document formats (PDF, text, markdown, etc.)- - Automatic integration with meta-search for unified queries+## Configuration System-## Example Research: Fusion Energy Developments+The package automatically creates and manages configuration files in your user directory:-The repository includes complete research examples demonstrating the tool's capabilities. For instance, our [fusion energy research analysis](https://github.com/LearningCircuit/local-deep-research/blob/main/examples/fusion-energy-research-developments.md) provides a comprehensive overview of:+- **Windows**: `Documents\LearningCircuit\local-deep-research\config\`+- **Linux/Mac**: `~/.config/local_deep_research/config/`-- Latest scientific breakthroughs in fusion research (2022-2025)-- Private sector funding developments exceeding $6 billion-- Expert projections for commercial fusion energy timelines-- Regulatory frameworks being developed for fusion deployment-- Technical challenges that must be overcome for commercial viability+### Default Configuration Files-This example showcases the system's ability to perform multiple research iterations, follow evidence trails across scientific and commercial domains, and synthesize information from diverse sources while maintaining proper citation.+When you first run the tool, it creates these configuration files:-## Installation+| File | Purpose |+|------|---------|+| `settings.toml` | General settings for research, web interface, and search |+| `llm_config.py` | Configure which LLM to use (local or cloud-based) |+| `search_engines.toml` | Define and configure search engines |+| `local_collections.toml` | Configure local document collections for RAG |+| `.secrets.toml` | Store API keys for cloud services |-1. Clone the repository:-```bash-git clone https://github.com/LearningCircuit/local-deep-research.git-cd local-deep-research-```-(experimental pip install with new features (but not so well tested yet): **pip install local-deep-research** )-2. Install dependencies:-```bash-pip install -r requirements.txt-playwright install-```+## Setting Up AI Models-3. Install Ollama (for local models):-```bash-# Install Ollama from https://ollama.ai-ollama pull mistral # Default model - many work really well choose best for your hardware (fits in GPU)-```+You can use either local or cloud-based models:-4. Configure environment variables:-```bash-# Copy the template-cp .env.template .env-```+### Local Models (via Ollama)-## Experimental install-```bash-#experimental pip install with new features (but not so well tested yet):-pip install local-deep-research-playwright install-ollama pull mistral-```-## Community & Support+1. [Install Ollama](https://ollama.ai)+2. Pull a model: `ollama pull gemma3:12b` (recommended model)+3. Ollama runs on port 11434 by default-We've just launched our [Discord server](https://discord.gg/2E6gYU2Z) for this project!+### Cloud Models-Our Discord server can help to exchange ideas about research approaches, discuss advanced usage patterns, and share other ideas.+Edit your `.secrets.toml` file to add API keys:-# Edit .env with your API keys (if using cloud LLMs)-ANTHROPIC_API_KEY=your-api-key-here # For Claude-OPENAI_API_KEY=your-openai-key-here # For GPT models-GUARDIAN_API_KEY=your-guardian-api-key-here # For The Guardian search+```toml+ANTHROPIC_API_KEY = "your-api-key-here" # For Claude models+OPENAI_API_KEY = "your-openai-key-here" # For GPT models```-## Usage-Terminal usage (not recommended):-```bash-python main.py+Then edit `llm_config.py` to change the default provider:++```python+# Change from OLLAMA to OPENAI or ANTHROPIC+DEFAULT_PROVIDER = ModelProvider.OPENAI+DEFAULT_MODEL = "gpt-4o" # Choose your model```-### Web Interface+## Setting Up Search Engines-The project includes a web interface for a more user-friendly experience:+The system includes multiple search engines. Some require API keys:-```bash-python app.py+```toml+# Add to .secrets.toml+SERP_API_KEY = "your-serpapi-key-here" # For Google results via SerpAPI+GOOGLE_PSE_API_KEY = "your-google-key-here" # For Google Programmable Search+GOOGLE_PSE_ENGINE_ID = "your-pse-id-here" # For Google Programmable Search+BRAVE_API_KEY = "your-brave-search-key-here" # For Brave Search+GUARDIAN_API_KEY = "your-guardian-key-here" # For The Guardian```-This will start a local web server, accessible at `http://127.0.0.1:5000` in your browser.+No API key required for: Wikipedia, arXiv, PubMed, Semantic Scholar, and local collections.-#### Web Interface Features:+## Local Document Search (RAG)-- **Dashboard**: Intuitive interface for starting and managing research queries-- **Real-time Updates**: Track research progress with live updates-- **Research History**: Access and manage past research queries-- **PDF Export**: Download completed research reports as PDF documents-- **Research Management**: Terminate ongoing research processes or delete past records+The system can search through your local documents using vector embeddings.---### Configuration-**Please report your best settings in issues so we can improve the default settings.**+### Setting Up Document Collections-Key settings in `config.py`:-```python-# LLM Configuration-DEFAULT_MODEL = "mistral" # Change based on your needs-DEFAULT_TEMPERATURE = 0.7-MAX_TOKENS = 8000--# Search Configuration-MAX_SEARCH_RESULTS = 40-SEARCH_REGION = "us-en"-TIME_PERIOD = "y"-SAFE_SEARCH = True-SEARCH_SNIPPETS_ONLY = False--# Choose search tool: "wiki", "arxiv", "duckduckgo", "guardian", "serp", "local_all", or "auto"-search_tool = "auto" # "auto" will intelligently select the best search engine for your query+1. Define collections in `local_collections.toml`. Default collections include:++```toml+[project_docs]+name = "Project Documents"+description = "Project documentation and specifications"+paths = ["@format ${DOCS_DIR}/project_documents"]+enabled = true+embedding_model = "all-MiniLM-L6-v2"+embedding_device = "cpu"+embedding_model_type = "sentence_transformers"+max_results = 20+max_filtered_results = 5+chunk_size = 1000+chunk_overlap = 200+cache_dir = "__CACHE_DIR__/local_search/project_docs"++# More collections defined in the file...```-## Local Document Search (RAG)+2. Create your document directories:+ - The `${DOCS_DIR}` variable points to a default location in your Documents folder+ - Documents are automatically indexed when the search is first used-The system includes powerful local document search capabilities using Retrieval-Augmented Generation (RAG). This allows you to search and retrieve content from your own document collections.+### Using Local Search-### Setting Up Local Collections+You can use local document search in several ways:-Create a file named `local_collections.py` in the project root directory:+1. **Auto-selection**: Set `tool = "auto"` in `settings.toml` [search] section+2. **Explicit collection**: Set `tool = "project_docs"` to search only that collection+3. **All collections**: Set `tool = "local_all"` to search across all collections+4. **Query syntax**: Type `collection:project_docs your query` to target a specific collection-```python-# local_collections.py-import os-from typing import Dict, Any--# Registry of local document collections-LOCAL_COLLECTIONS = {- # Research Papers Collection- "research_papers": {- "name": "Research Papers",- "description": "Academic research papers and articles",- "paths": [os.path.abspath("local_search_files/research_papers")], # Use absolute paths- "enabled": True,- "embedding_model": "all-MiniLM-L6-v2",- "embedding_device": "cpu",- "embedding_model_type": "sentence_transformers",- "max_results": 20,- "max_filtered_results": 5,- "chunk_size": 800, # Smaller chunks for academic content- "chunk_overlap": 150,- "cache_dir": ".cache/local_search/research_papers"- },-- # Personal Notes Collection- "personal_notes": {- "name": "Personal Notes",- "description": "Personal notes and documents",- "paths": [os.path.abspath("local_search_files/personal_notes")], # Use absolute paths- "enabled": True,- "embedding_model": "all-MiniLM-L6-v2",- "embedding_device": "cpu",- "embedding_model_type": "sentence_transformers",- "max_results": 30,- "max_filtered_results": 10,- "chunk_size": 500, # Smaller chunks for notes- "chunk_overlap": 100,- "cache_dir": ".cache/local_search/personal_notes"- }-}-```+## Advanced Configuration-Create directories for your collections:+### Research Parameters-```bash-mkdir -p local_search_files/research_papers-mkdir -p local_search_files/personal_notes-```+Edit `settings.toml` to customize research parameters:-Add your documents to these folders, and the system will automatically index them and make them available for searching.+```toml+[search]+# Search tool to use (auto, wikipedia, arxiv, etc.)+tool = "auto"-### Using Local Search+# Number of research cycles+iterations = 2++# Questions generated per cycle+questions_per_iteration = 2-You can use local search in several ways:+# Results per search query+max_results = 50-1. **Auto-selection**: Set `search_tool = "auto"` in `config.py` and the system will automatically use your local collections when appropriate for the query.+# Results after relevance filtering+max_filtered_results = 5-2. **Explicit Selection**: Set `search_tool = "research_papers"` to search only that specific collection.+# More settings available...+```-3. **Search All Local Collections**: Set `search_tool = "local_all"` to search across all your local document collections.+### LLM Configuration-4. **Query Syntax**: Use `collection:collection_name your query` to target a specific collection within a query.+Edit `llm_config.py` to configure language models:++```python+# Provider enum+class ModelProvider(Enum):+ OLLAMA = auto()+ OPENAI = auto()+ ANTHROPIC = auto()+ # More providers available...-### Search Engine Options+# Set your preferred model provider here+DEFAULT_PROVIDER = ModelProvider.OLLAMA-The system supports multiple search engines that can be selected by changing the `search_tool` variable in `config.py`:+# Set your default model name here+DEFAULT_MODEL = "gemma3:12b" # Default recommended model-- **Auto** (`auto`): Intelligent search engine selector that analyzes your query and chooses the most appropriate source (Wikipedia, arXiv, local collections, etc.)-- **SearXNG** (`searxng`): Local web-search engine, great for privacy, no API key required (requires a searxng server)-- **Wikipedia** (`wiki`): Best for general knowledge, facts, and overview information-- **arXiv** (`arxiv`): Great for scientific and academic research, accessing preprints and papers-- **PubMed** (`pubmed`): Excellent for biomedical literature, medical research, and health information-- **DuckDuckGo** (`duckduckgo`): General web search that doesn't require an API key-- **The Guardian** (`guardian`): Quality journalism and news articles (requires an API key)-- **SerpAPI** (`serp`): Google search results (requires an API key)-- **Google Programmable Search Engine** (`google_pse`): Custom search experiences with control over search scope and domains (requires API key and search engine ID)-- **Local Collections**: Any collections defined in your `local_collections.py` file+# More settings available...+```-> **Note:** The "auto" option will intelligently select the best search engine based on your query. For example, if you ask about physics research papers, it might select arXiv or your research_papers collection, while if you ask about current events, it might select The Guardian or DuckDuckGo.+## Available Search Engines++| Engine | Purpose | API Key Required? |+|--------|---------|-------------------|+| `auto` | Intelligently selects the best engine | No |+| `wikipedia` | General knowledge and facts | No |+| `arxiv` | Scientific papers and research | No |+| `pubmed` | Medical and biomedical research | No |+| `semantic_scholar` | Academic literature across all fields | No |+| `github` | Code repositories and documentation | No (but rate-limited) |+| `brave` | Web search (privacy-focused) | Yes |+| `serpapi` | Google search results | Yes |+| `google_pse` | Custom Google search | Yes |+| Any collection name | Search your local documents | No |> **Support Free Knowledge:** If you frequently use the search engines in this tool, please consider making a donation to these organizations. They provide valuable services and rely on user support to maintain their operations:> - [Donate to Wikipedia](https://donate.wikimedia.org)@@ -248,25 +228,70 @@ The system supports multiple search engines that can be selected by changing the> - [Donate to DuckDuckGo](https://duckduckgo.com/donations)> - [Support PubMed/NCBI](https://www.nlm.nih.gov/pubs/donations/donations.html)+## Web Interface++The web interface offers several features:++- **Dashboard**: Start and manage research queries+- **Real-time Updates**: Track research progress+- **Research History**: Access past queries+- **PDF Export**: Download reports+- **Research Management**: Terminate processes or delete records++## Command Line Interface++The CLI version allows you to:++1. Choose between a quick summary or detailed report+2. Enter your research query+3. View results directly in the terminal+4. Save reports automatically to the configured output directory++## Development Setup++If you want to develop or modify the package, you can install it in development mode:++```bash+# Clone the repository+git clone https://github.com/LearningCircuit/local-deep-research.git+cd local-deep-research++# Install in development mode+pip install -e .+```++This creates an "editable" installation that uses your local code, so any changes you make are immediately available without reinstalling.++You can run the application directly using Python module syntax:++```bash+# Run the web interface+python -m local_deep_research.web.app++# Run the CLI version (not recommended)+python -m local_deep_research.main+```++This approach is useful for development and debugging, as it provides more detailed error messages and allows you to make code changes on the fly.++## Example Research++The repository includes complete research examples like our [fusion energy research analysis](https://github.com/LearningCircuit/local-deep-research/blob/main/examples/fusion-energy-research-developments.md) showcasing the system's capabilities.++## Community & Support++Join our [Discord server](https://discord.gg/2E6gYU2Z) to exchange ideas, discuss usage patterns, and share research approaches.+## License-This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.+This project is licensed under the MIT License.## Acknowledgments+- Built with [Ollama](https://ollama.ai) for local AI processing-- Search powered by multiple sources:- - [Wikipedia](https://www.wikipedia.org/) for factual knowledge (default search engine)- - [arXiv](https://arxiv.org/) for scientific papers- - [PubMed](https://pubmed.ncbi.nlm.nih.gov/) for biomedical literature- - [DuckDuckGo](https://duckduckgo.com) for web search- - [The Guardian](https://www.theguardian.com/) for quality journalism- - [SerpAPI](https://serpapi.com) for Google search results (requires API key)- - [SearXNG](https://searxng.org/) for local web-search engine+- Multiple integrated search engines including Wikipedia, arXiv, PubMed, and more- Built on [LangChain](https://github.com/hwchase17/langchain) framework-- Uses [justext](https://github.com/miso-belica/justext) for content extraction-- [Playwright](https://playwright.dev) for web content retrieval-- Uses [FAISS](https://github.com/facebookresearch/faiss) for vector similarity search-- Uses [sentence-transformers](https://github.com/UKPLab/sentence-transformers) for embeddings+- Uses [justext](https://github.com/miso-belica/justext), [Playwright](https://playwright.dev), [FAISS](https://github.com/facebookresearch/faiss), and more## Contributing@@ -276,8 +301,4 @@ Contributions are welcome! Please feel free to submit a Pull Request.2. Create your feature branch (`git checkout -b feature/AmazingFeature`)3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)4. Push to the branch (`git push origin feature/AmazingFeature`)-5. Open a Pull Request--## Star History-- [](https://www.star-history.com/#LearningCircuit/local-deep-research&Date)+5. Open a Pull Request\ No newline at end of filediff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex 47d7e2525b..3c70ca61c0 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -15,10 +15,6 @@ class IntegratedReportGenerator:searches_per_section # Control search depth per section)- def _remove_think_tags(self, text: str) -> str:- print(text)- return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()-def generate_report(self, initial_findings: Dict, query: str) -> Dict:"""Generate a complete research report with section-specific research."""@@ -63,7 +59,7 @@ class IntegratedReportGenerator:Each subsection must include its purpose after the | symbol."""- response = self._remove_think_tags(self.model.invoke(prompt).content)+ response = search_utilities.remove_think_tags(self.model.invoke(prompt).content)# Parse the structurestructure = []