Ollama web search: check search results against the page text
Use web_search for titles, URLs and snippets, then read one page with web_fetch and compare the page text against the snippet.
Task and deliverable · Prepare the input and environment · Mechanism and data flow
At a glance
Use Ollama’s search endpoint to obtain candidates, fetch one selected URL, and compare the snippet with the returned page text to produce a traceable record. API fields and behavior come from the official documentation; composing the calls, validating the text, choosing stopping conditions and cleaning up are editorial recommendations. No API was called, software installed or actual output observed in this batch.
Task workflow
Authentication and the cloud boundary
Web search is a REST API hosted by Ollama, with requests going to
https://ollama.com/api/web_searchandhttps://ollama.com/api/web_fetch, so it is not a local offline service. The documentation says you must create an API key and have a free Ollama account. The examples send the key asAuthorization: Bearer $OLLAMA_API_KEYand warn thatOLLAMA_API_KEYmust be set, or the key must be passed in theAuthorizationheader. The page does not describe how the server handles requests, and it states no price or usage limit.Search layer: query and results
web_searchruns one search for a single query. In the request body,queryis a required string andmax_resultsis an optional integer, with a default of 5 and a maximum of 10. The response is an object with aresultsarray, and each item hastitle,urlandcontent. Thecontentfield is a relevant snippet from the page, not the full page text. Search results are therefore leads: they tell you which URL may be relevant and show a short piece of its text.Fetch layer: url and content
web_fetchreads a single page by URL, andurlis a required string in the request body. The response is an object withtitle,contentandlinks: the page title, its main content, and an array of links found on the page. This endpoint is what lets you check the original text. You take aurlfrom the search results, fetch the fullercontent, and compare it with the search snippet.Linking the two calls and context length
The two endpoints are independent. None of the documented curl or Python examples passes search results to the fetch call automatically, so you choose a URL from
resultsand enter it in the fetch request. The page also says search results can run to thousands of tokens, and recommends raising the model context length to at least about 32000 tokens if you hand the results to a model. That advice applies when a model receives the results; the direct requests below need only the endpoints and a key.
Task and deliverable
Use Ollama’s search endpoint to obtain candidates, fetch one selected URL, and compare the snippet with the returned page text to produce a traceable record. API fields and behavior come from the official documentation; composing the calls, validating the text, choosing stopping conditions and cleaning up are editorial recommendations. No API was called, software installed or actual output observed in this batch.
Prepare the input and environment
- An Ollama account and an API key. The documentation says an API key is needed for the web search API and that a free Ollama account is required. The docs navigation lists a Creating an API key page, which was not read in this batch.
OLLAMA_API_KEYset in the environment that sends the request, or the key passed in theAuthorizationheader. The documented examples pass it inBearerform.- One public research question and one public web page you are allowed to read.
- If you use Python, the documented examples use the
ollamalibrary. The page gives no install command or version requirement, and this tutorial adds none, so check the official instructions yourself.
Mechanism and data flow
Authentication and the cloud boundary:Web search is a REST API hosted by Ollama, with requests going to https://ollama.com/api/web_search and https://ollama.com/api/web_fetch, so it is not a local offline service. The documentation says you must create an API key and have a free Ollama account. The examples send the key as Authorization: Bearer $OLLAMA_API_KEY and warn that OLLAMA_API_KEY must be set, or the key must be passed in the Authorization header. The page does not describe how the server handles requests, and it states no price or usage limit.
Search layer: query and results:web_search runs one search for a single query. In the request body, query is a required string and max_results is an optional integer, with a default of 5 and a maximum of 10. The response is an object with a results array, and each item has title, url and content. The content field is a relevant snippet from the page, not the full page text. Search results are therefore leads: they tell you which URL may be relevant and show a short piece of its text.
Fetch layer: url and content:web_fetch reads a single page by URL, and url is a required string in the request body. The response is an object with title, content and links: the page title, its main content, and an array of links found on the page. This endpoint is what lets you check the original text. You take a url from the search results, fetch the fuller content, and compare it with the search snippet.
Linking the two calls and context length:The two endpoints are independent. None of the documented curl or Python examples passes search results to the fetch call automatically, so you choose a URL from results and enter it in the fetch request. The page also says search results can run to thousands of tokens, and recommends raising the model context length to at least about 32000 tokens if you hand the results to a model. That advice applies when a model receives the results; the direct requests below need only the endpoints and a key.
Workflow map
| Stage | What happens |
|---|---|
| Authentication and the cloud boundary | Web search is a REST API hosted by Ollama, with requests going to https://ollama.com/api/web_search and https://ollama.com/api/web_fetch, so it is not a local offline service. |
| Search layer: query and results | web_search runs one search for a single query. |
| Fetch layer: url and content | web_fetch reads a single page by URL, and url is a required string in the request body. |
| Linking the two calls and context length | The two endpoints are independent. |
Complete the task
Write down the question and the allowed pages:Write the public question you want to verify in one sentence, and confirm you will read only public pages you are allowed to read. The documented example question is what is ollama?. Shorten your question into a query that fits in query, and note the exact claim you plan to check, so you have something to compare against later. This step calls no endpoint.
Prepare the account and key:Creating an API key requires a free Ollama account. Set OLLAMA_API_KEY in the terminal environment that will send the request, or put the key in the Authorization header as the docs show. For the exact creation screens, use the official Creating an API key page, which this batch did not read. Keep the key out of notes and screenshots you plan to share.
Send the search request:Use the documented curl search example to send a JSON request containing query to https://ollama.com/api/web_search, or call ollama.web_search in Python. The examples use what is ollama? and What is Ollama?; replace them with your own question. Neither example sets max_results, so the documented maximum defaults to 5 results. If you want more candidates, add the field yourself, up to 10.
Inspect the results and pick a URL:Read each title, url and content. Choose the result whose URL bears directly on your question, and see whether its content snippet mentions the claim you want to check. Results can mix official and third-party pages, as the documented example does, so decide which kind of source should answer your question before you copy the url.
Send the fetch request:Use the documented web_fetch curl example: a POST to https://ollama.com/api/web_fetch with the Authorization header and Content-Type: application/json, and the URL you picked in the url field. In Python you can use from ollama import web_fetch. The curl example writes url as ollama.com and the Python example as https://ollama.com, so both forms appear in the docs. Copy the URL exactly from the search results to avoid spelling differences.
Compare the page text with the snippet and record it:Read the returned content and find the sentence that matches the search snippet. Decide whether the page text supports the claim you are checking. Then see whether title matches the search result and whether links holds pages worth checking next. Save one record: the question, the query, the chosen url, the fetched title, and the page sentence that supports or fails to support the claim.
Stop and clean up:The documented examples only print their results and write no files. When you finish, delete any page excerpts you no longer need under your own rules, and unset OLLAMA_API_KEY in any terminal you are done with, so the key is not left in shared files. The source does not describe revoking or deleting a key; check the official API key page if you need that.
Worked example
Take the documented example as the base: the query what is ollama? returns a response whose results array has three items. The first item has title set to Ollama, url set to https://ollama.com/, and a content that starts with Cloud models are now available.... Passing that URL to web_fetch, the documented result has the same title, Ollama. Its content begins with a Markdown link to the cloud models blog post followed by are now available in Ollama, and its links include https://ollama.com/models and https://github.com/ollama/ollama. The record could then read: the question is what Ollama is, the source is the official home page, and the fetched text and the search snippet point to the same sentence. These outputs are illustrations from the official docs. They are not observations from this batch, and they do not show current page content or search ranking.
curl https://ollama.com/api/web_search \
--header "Authorization: Bearer $OLLAMA_API_KEY" \
-d '{
"query":"what is ollama?"
}'
import ollama
response = ollama.web_search("What is Ollama?")
print(response)
curl --request POST \
--url https://ollama.com/api/web_fetch \
--header "Authorization: Bearer $OLLAMA_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"url": "ollama.com"
}'
from ollama import web_fetch
result = web_fetch('https://ollama.com')
print(result)
Check the result and failure paths
- Expected search success: the response is an object with a
resultsarray, each item hastitle,urlandcontent, and the count does not exceedmax_results, or 5 when it is not set. - Expected fetch success: the response has
title,contentandlinks, and you can find the text matching the search snippet insidecontent. - Failure or stop signals: no key set, an empty
results, missing fields, a chosen URL that cannot be read, or page text that does not match the snippet. Stop and recheck your inputs, and do not quote the snippet as if it were the page text. The page lists no error codes, so rely on the response you actually receive. - Delivery check: every conclusion in your record points back to one
urland one sentence of fetched text. - Editorial recommendation: stop this verification attempt when results are empty, a request fails, the text does not match, or the user chooses to stop. In every exit path, keep only the needed record under your retention rules and clear the terminal key when it is no longer in use. This tutorial supplies no API for cancelling an in-flight request.
Scope and limits
- This is a cloud API, not a local offline service. The page states no price or usage limit, so check the official documentation before relying on it.
- The documented output is only an illustration. It does not represent current page content or search ranking, and it does not promise that you will get the same results.
- A search snippet is not the page text. The docs call the fetched
contentthe main content of the page and do not say it matches the full page. - This tutorial covers only public pages you are allowed to read; pages that need a login are out of scope.
- The docs page does not say how to install the Python
ollamalibrary or which version is needed, and this tutorial does not fill that in.
No product or API was run in this batch, and no code was installed or executed. The content relies only on the official documentation page s1, and the example outputs are the ones the documentation shows, not observations from this batch.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.