mirror of
https://github.com/hwchase17/langchain.git
synced 2025-12-17 21:05:17 +00:00
Thank you for contributing to LangChain!
- [x] **PR title**: "package: description"
- Where "package" is whichever of langchain, core, etc. is being
modified. Use "docs: ..." for purely docs changes, "infra: ..." for CI
changes.
- Example: "core: add foobar LLM"
- [x] **PR message**: ***Delete this entire checklist*** and replace
with
- **Description:** a description of the change
- **Issue:** the issue # it fixes, if applicable
- **Dependencies:** any dependencies required for this change
- **Twitter handle:** if your PR gets announced, and you'd like a
mention, we'll gladly shout you out!
- [x] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.
- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/
Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
If no one reviews your PR within a few days, please @-mention one of
baskaryan, eyurtsev, ccurme, vbarda, hwchase17.
91 lines
2.9 KiB
Plaintext
91 lines
2.9 KiB
Plaintext
# SearxNG Search API
|
|
|
|
This page covers how to use the SearxNG search API within LangChain.
|
|
It is broken into two parts: installation and setup, and then references to the specific SearxNG API wrapper.
|
|
|
|
## Installation and Setup
|
|
|
|
While it is possible to utilize the wrapper in conjunction with [public searx
|
|
instances](https://searx.space/) these instances frequently do not permit API
|
|
access (see note on output format below) and have limitations on the frequency
|
|
of requests. It is recommended to opt for a self-hosted instance instead.
|
|
|
|
### Self Hosted Instance:
|
|
|
|
See [this page](https://searxng.github.io/searxng/admin/installation.html) for installation instructions.
|
|
|
|
When you install SearxNG, the only active output format by default is the HTML format.
|
|
You need to activate the `json` format to use the API. This can be done by adding the following line to the `settings.yml` file:
|
|
```yaml
|
|
search:
|
|
formats:
|
|
- html
|
|
- json
|
|
```
|
|
You can make sure that the API is working by issuing a curl request to the API endpoint:
|
|
|
|
`curl -kLX GET --data-urlencode q='langchain' -d format=json http://localhost:8888`
|
|
|
|
This should return a JSON object with the results.
|
|
|
|
|
|
## Wrappers
|
|
|
|
### Utility
|
|
|
|
To use the wrapper we need to pass the host of the SearxNG instance to the wrapper with:
|
|
1. the named parameter `searx_host` when creating the instance.
|
|
2. exporting the environment variable `SEARXNG_HOST`.
|
|
|
|
You can use the wrapper to get results from a SearxNG instance.
|
|
|
|
```python
|
|
from langchain_community.utilities import SearxSearchWrapper
|
|
s = SearxSearchWrapper(searx_host="http://localhost:8888")
|
|
s.run("what is a large language model?")
|
|
```
|
|
|
|
### Tool
|
|
|
|
You can also load this wrapper as a Tool (to use with an Agent).
|
|
|
|
You can do this with:
|
|
|
|
```python
|
|
from langchain_community.agent_toolkits.load_tools import load_tools
|
|
tools = load_tools(["searx-search"],
|
|
searx_host="http://localhost:8888",
|
|
engines=["github"])
|
|
```
|
|
|
|
Note that we could _optionally_ pass custom engines to use.
|
|
|
|
If you want to obtain results with metadata as *json* you can use:
|
|
```python
|
|
tools = load_tools(["searx-search-results-json"],
|
|
searx_host="http://localhost:8888",
|
|
num_results=5)
|
|
```
|
|
|
|
#### Quickly creating tools
|
|
|
|
This examples showcases a quick way to create multiple tools from the same
|
|
wrapper.
|
|
|
|
```python
|
|
from langchain_community.tools.searx_search.tool import SearxSearchResults
|
|
|
|
wrapper = SearxSearchWrapper(searx_host="**")
|
|
github_tool = SearxSearchResults(name="Github", wrapper=wrapper,
|
|
kwargs = {
|
|
"engines": ["github"],
|
|
})
|
|
|
|
arxiv_tool = SearxSearchResults(name="Arxiv", wrapper=wrapper,
|
|
kwargs = {
|
|
"engines": ["arxiv"]
|
|
})
|
|
```
|
|
|
|
For more information on tools, see [this page](/docs/how_to/tools_builtin).
|