Utility for using SearxNG meta search API.
SearxNG is a privacy-friendly free metasearch engine that aggregates results from
multiple search engines <https://docs.searxng.org/admin/engines/configured_engines.html>_ and databases and
supports the OpenSearch <https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md>_
specification.
More details on the installation instructions here. <../../integrations/searx.html>_
For the search API refer to https://docs.searxng.org/dev/search_api.html
In order to use this utility you need to provide the searx host. This can be done
by passing the named parameter :attr:searx_host <SearxSearchWrapper.searx_host>
or exporting the environment variable SEARX_HOST.
Note: this is the only required parameter.
Then create a searx search instance like this:
.. code-block:: python
from langchain_community.utilities import SearxSearchWrapper
# when the host starts with `http` SSL is disabled and the connection
# is assumed to be on a private network
searx_host='http://self.hosted'
search = SearxSearchWrapper(searx_host=searx_host)
You can now use the search instance to query the searx API.
Use the :meth:run() <SearxSearchWrapper.run> and
:meth:results() <SearxSearchWrapper.results> methods to query the searx API.
Other methods are available for convenience.
:class:SearxResults is a convenience wrapper around the raw json result.
Example usage of the run method to make a search:
.. code-block:: python
s.run(query="what is the best search engine?")
You can pass any accepted searx search API <https://docs.searxng.org/dev/search_api.html>_ parameters to the
:py:class:SearxSearchWrapper instance.
In the following example we are using the
:attr:engines <SearxSearchWrapper.engines> and the language parameters:
.. code-block:: python
# assuming the searx host is set as above or exported as an env variable
s = SearxSearchWrapper(engines=['google', 'bing'],
language='es')
Searx offers a special
search syntax <https://docs.searxng.org/user/index.html#search-syntax>_
that can also be used instead of passing engine parameters.
For example the following query:
.. code-block:: python
s = SearxSearchWrapper("langchain library", engines=['github'])
# can also be written as:
s = SearxSearchWrapper("langchain library !github")
# or even:
s = SearxSearchWrapper("langchain library !gh")
In some situations you might want to pass an extra string to the search query.
For example when the run() method is called by an agent. The search suffix can
also be used as a way to pass extra parameters to searx or the underlying search
engines.
.. code-block:: python
# select the github engine and pass the search suffix
s = SearchWrapper("langchain library", query_suffix="!gh")
s = SearchWrapper("langchain library")
# select github the conventional google search syntax
s.run("large language models", query_suffix="site:github.com")
NOTE: A search suffix can be defined on both the instance and the method level. The resulting query will be the concatenation of the two with the former taking precedence.
See SearxNG Configured Engines <https://docs.searxng.org/admin/engines/configured_engines.html>_ and
SearxNG Search Syntax <https://docs.searxng.org/user/index.html#id1>_
for more details.
This wrapper is based on the SearxNG fork https://github.com/searxng/searxng which is better maintained than the original Searx project and offers more features.
Public searxNG instances often use a rate limiter for API usage, so you might want to use a self hosted instance and disable the rate limiter.
If you are self-hosting an instance you can customize the rate limiter for your
own network as described
here <https://docs.searxng.org/src/searx.botdetection.html#limiter-src>_.
For a list of public SearxNG instances see https://searx.space/
Dict like wrapper around search api results.
Wrapper for Searx API.
To use you need to provide the searx host by passing the named parameter
searx_host or exporting the environment variable SEARX_HOST.
In some situations you might want to disable SSL verification, for example
if you are running searx locally. You can do this by passing the named parameter
unsecure. You can also pass the host url scheme as http to disable SSL.