LlamaIndex orchestrates retrieval over your data. ODEN adds the live web to that mix as a tool or a custom retriever — in a few lines, since ODEN is a plain HTTP API.
As a LlamaIndex tool#
import os, requests
from llama_index.core.tools import FunctionTool
def oden_web_search(query: str) -> str:
"""Search the live web and return a synthesized answer with citations."""
r = requests.post(
"https://api.oden-api.com/search",
headers={"Authorization": f"Bearer {os.environ['ODEN_KEY']}"},
json={"query": query, "include_snippets": True},
timeout=30,
)
r.raise_for_status()
d = r.json()["results"]
cites = "\n".join(f"- {c['title']}: {c['url']}" for c in d["citations"])
return f"{d.get('answer','')}\n\nSources:\n{cites}"
oden_tool = FunctionTool.from_defaults(fn=oden_web_search)
# Pass [oden_tool] to a ReActAgent or FunctionAgent
As a custom retriever#
Return ODEN citations as LlamaIndex nodes so they flow through a query engine:
import os, requests
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import NodeWithScore, TextNode
class OdenRetriever(BaseRetriever):
def _retrieve(self, query_bundle):
r = requests.post(
"https://api.oden-api.com/search",
headers={"Authorization": f"Bearer {os.environ['ODEN_KEY']}"},
json={"query": query_bundle.query_str, "include_snippets": True},
timeout=30,
)
r.raise_for_status()
out = []
for c in r.json()["results"]["citations"]:
node = TextNode(text=c.get("snippet", c["title"]),
metadata={"title": c["title"], "url": c["url"]})
out.append(NodeWithScore(node=node, score=c["score"]))
return out
Notes#
- The tool is best for agents that decide when to search; the retriever is best for query engines that expect nodes.
scoremaps straight ontoNodeWithScore, so LlamaIndex ranking works out of the box.- Combine
OdenRetrieverwith your own index retriever for hybrid private + web retrieval.
FAQ#
Can I combine ODEN with a LlamaIndex vector index?#
Yes. Use a router or a composable retriever: your vector index for private data, OdenRetriever for the live web.
Does ODEN return LlamaIndex nodes directly?#
No — it returns JSON. The OdenRetriever above maps that JSON to NodeWithScore in a few lines.
Which is better, tool or retriever?#
Tool for agentic flows where the model chooses to search; retriever for deterministic query engines. Many apps use both.