7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
155 lines
4.5 KiB
Markdown
155 lines
4.5 KiB
Markdown
# Elasticsearch Search Engine
|
|
|
|
This document describes how to use and configure the Elasticsearch search engine within the Local Deep Research project.
|
|
|
|
## Overview
|
|
|
|
The Elasticsearch search engine allows you to search for documents within Elasticsearch indices. This is particularly useful for scenarios requiring searches across large volumes of structured or unstructured text data.
|
|
|
|
## Prerequisites
|
|
|
|
1. A running Elasticsearch server (local or remote).
|
|
2. Elasticsearch Python client library: `elasticsearch>=8.10.0`.
|
|
|
|
## Installation
|
|
|
|
Ensure that you have installed the `elasticsearch` Python package. If you are installing Local Deep Research from source, you can run:
|
|
|
|
```bash
|
|
pip install elasticsearch>=8.10.0
|
|
```
|
|
|
|
## Basic Usage
|
|
|
|
### Usage in Code
|
|
|
|
```python
|
|
from local_deep_research.web_search_engines.engines.search_engine_elasticsearch import ElasticsearchSearchEngine
|
|
|
|
# Create search engine instance
|
|
es_search = ElasticsearchSearchEngine(
|
|
hosts=["http://localhost:9200"], # List of Elasticsearch hosts
|
|
index_name="my_index", # Name of the index to search
|
|
username="user", # Optional: Authentication username
|
|
password="pass", # Optional: Authentication password
|
|
max_results=10 # Maximum number of results to return
|
|
)
|
|
|
|
# Execute search
|
|
results = es_search.run("Your search query")
|
|
|
|
# Process results
|
|
for result in results:
|
|
print(f"Title: {result.get('title')}")
|
|
print(f"Snippet: {result.get('snippet')}")
|
|
print(f"Content: {result.get('content')}")
|
|
```
|
|
|
|
### Advanced Search
|
|
|
|
The ES search engine supports various advanced search methods:
|
|
|
|
```python
|
|
# Use Elasticsearch Query String syntax
|
|
results = es_search.search_by_query_string("title:keyword AND content:search_text")
|
|
|
|
# Use Elasticsearch DSL (Domain Specific Language)
|
|
results = es_search.search_by_dsl({
|
|
"query": {
|
|
"bool": {
|
|
"must": {"match": {"content": "search term"}},
|
|
"filter": {"term": {"category": "technology"}}
|
|
}
|
|
}
|
|
})
|
|
```
|
|
|
|
## Configuration
|
|
|
|
### Search Engine Parameters
|
|
|
|
| Parameter | Type | Default Value | Description |
|
|
| :--- | :--- | :--- | :--- |
|
|
| hosts | List[str] | ["http://localhost:9200"] | List of Elasticsearch server addresses |
|
|
| index_name | str | "documents" | Name of the index to search |
|
|
| username | Optional[str] | None | Authentication username |
|
|
| password | Optional[str] | None | Authentication password |
|
|
| api_key | Optional[str] | None | API Key authentication |
|
|
| cloud_id | Optional[str] | None | Elastic Cloud ID |
|
|
| max_results | int | 10 | Maximum number of results |
|
|
| highlight_fields | List[str] | ["content", "title"] | Fields to highlight |
|
|
| search_fields | List[str] | ["content", "title"] | Fields to search |
|
|
| filter_query | Optional[Dict] | None | Optional filter query |
|
|
| llm | Optional[BaseLLM] | None | LLM for relevance filtering |
|
|
| max_filtered_results | Optional[int] | None | Maximum number of filtered results |
|
|
|
|
## Indexing Data
|
|
|
|
For ease of use, we provide the `ElasticsearchManager` utility class to help index data:
|
|
|
|
```python
|
|
from local_deep_research.utilities.es_utils import ElasticsearchManager
|
|
|
|
# Create ES Manager
|
|
es_manager = ElasticsearchManager(
|
|
hosts=["http://localhost:9200"]
|
|
)
|
|
|
|
# Create index
|
|
es_manager.create_index("my_index")
|
|
|
|
# Index a single document
|
|
es_manager.index_document(
|
|
index_name="my_index",
|
|
document={
|
|
"title": "Document Title",
|
|
"content": "Document content...",
|
|
}
|
|
)
|
|
|
|
# Bulk index documents
|
|
documents = [
|
|
{"title": "Document 1", "content": "Content 1"},
|
|
{"title": "Document 2", "content": "Content 2"}
|
|
]
|
|
es_manager.bulk_index_documents("my_index", documents)
|
|
|
|
# Index file (automatically extract content)
|
|
es_manager.index_file("my_index", "path/to/document.pdf")
|
|
|
|
# Index all files in a directory
|
|
es_manager.index_directory(
|
|
"my_index",
|
|
"path/to/docs",
|
|
file_patterns=["*.pdf", "*.docx", "*.txt"]
|
|
)
|
|
```
|
|
|
|
## Examples
|
|
|
|
Refer to `examples/elasticsearch_search_example.py` for a complete usage example.
|
|
|
|
## Running Examples
|
|
|
|
Ensure Elasticsearch is running, then execute:
|
|
|
|
```bash
|
|
python examples/elasticsearch_search_example.py
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Cannot connect to Elasticsearch
|
|
|
|
- Ensure the Elasticsearch server is running.
|
|
- Verify the host address and port.
|
|
- Verify authentication credentials (if required).
|
|
- Check network connection and firewall settings.
|
|
|
|
### Empty Search Results
|
|
|
|
- Ensure the index exists and contains data.
|
|
- Check if the search fields are correct.
|
|
- Try using a simpler query.
|
|
- Check Elasticsearch logs for more information.
|