Update docs
This commit is contained in:
parent
cf9d6a116f
commit
57bac178dd
3 changed files with 84 additions and 18 deletions
43
README.md
43
README.md
|
|
@ -64,11 +64,12 @@ haiku-rag serve
|
||||||
```python
|
```python
|
||||||
from haiku.rag.client import HaikuRAG
|
from haiku.rag.client import HaikuRAG
|
||||||
from haiku.rag.research import (
|
from haiku.rag.research import (
|
||||||
|
PlanNode,
|
||||||
ResearchContext,
|
ResearchContext,
|
||||||
ResearchDeps,
|
ResearchDeps,
|
||||||
ResearchState,
|
ResearchState,
|
||||||
build_research_graph,
|
build_research_graph,
|
||||||
PlanNode,
|
stream_research_graph,
|
||||||
)
|
)
|
||||||
|
|
||||||
async with HaikuRAG("database.lancedb") as client:
|
async with HaikuRAG("database.lancedb") as client:
|
||||||
|
|
@ -90,22 +91,40 @@ async with HaikuRAG("database.lancedb") as client:
|
||||||
|
|
||||||
# Multi‑agent research pipeline (Plan → Search → Evaluate → Synthesize)
|
# Multi‑agent research pipeline (Plan → Search → Evaluate → Synthesize)
|
||||||
graph = build_research_graph()
|
graph = build_research_graph()
|
||||||
|
question = (
|
||||||
|
"What are the main drivers and trends of global temperature "
|
||||||
|
"anomalies since 1990?"
|
||||||
|
)
|
||||||
state = ResearchState(
|
state = ResearchState(
|
||||||
question=(
|
context=ResearchContext(original_question=question),
|
||||||
"What are the main drivers and trends of global temperature "
|
|
||||||
"anomalies since 1990?"
|
|
||||||
),
|
|
||||||
context=ResearchContext(original_question="…"),
|
|
||||||
max_iterations=2,
|
max_iterations=2,
|
||||||
confidence_threshold=0.8,
|
confidence_threshold=0.8,
|
||||||
max_concurrency=3,
|
max_concurrency=2,
|
||||||
)
|
)
|
||||||
deps = ResearchDeps(client=client)
|
deps = ResearchDeps(client=client)
|
||||||
start = PlanNode(provider=None, model=None)
|
|
||||||
result = await graph.run(start, state=state, deps=deps)
|
# Blocking run (final result only)
|
||||||
report = result.output
|
result = await graph.run(
|
||||||
print(report.title)
|
PlanNode(provider="openai", model="gpt-4o-mini"),
|
||||||
print(report.executive_summary)
|
state=state,
|
||||||
|
deps=deps,
|
||||||
|
)
|
||||||
|
print(result.output.title)
|
||||||
|
|
||||||
|
# Streaming progress (log/report/error events)
|
||||||
|
async for event in stream_research_graph(
|
||||||
|
graph,
|
||||||
|
PlanNode(provider="openai", model="gpt-4o-mini"),
|
||||||
|
state,
|
||||||
|
deps,
|
||||||
|
):
|
||||||
|
if event.type == "log":
|
||||||
|
iteration = event.state.iterations if event.state else state.iterations
|
||||||
|
print(f"[{iteration}] {event.message}")
|
||||||
|
elif event.type == "report":
|
||||||
|
print("\nResearch complete!\n")
|
||||||
|
print(event.report.title)
|
||||||
|
print(event.report.executive_summary)
|
||||||
```
|
```
|
||||||
|
|
||||||
## MCP Server
|
## MCP Server
|
||||||
|
|
|
||||||
|
|
@ -76,30 +76,75 @@ haiku-rag research "How does haiku.rag organize and query documents?" \
|
||||||
--verbose
|
--verbose
|
||||||
```
|
```
|
||||||
|
|
||||||
Python usage:
|
Python usage (blocking result):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from haiku.rag.client import HaikuRAG
|
from haiku.rag.client import HaikuRAG
|
||||||
from haiku.rag.research import (
|
from haiku.rag.research import (
|
||||||
|
PlanNode,
|
||||||
ResearchContext,
|
ResearchContext,
|
||||||
ResearchDeps,
|
ResearchDeps,
|
||||||
ResearchState,
|
ResearchState,
|
||||||
build_research_graph,
|
build_research_graph,
|
||||||
PlanNode,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async with HaikuRAG(path_to_db) as client:
|
async with HaikuRAG(path_to_db) as client:
|
||||||
graph = build_research_graph()
|
graph = build_research_graph()
|
||||||
|
question = "What are the main drivers and trends of global temperature anomalies since 1990?"
|
||||||
state = ResearchState(
|
state = ResearchState(
|
||||||
question="What are the main drivers and trends of global temperature anomalies since 1990?",
|
context=ResearchContext(original_question=question),
|
||||||
context=ResearchContext(original_question=... ),
|
|
||||||
max_iterations=2,
|
max_iterations=2,
|
||||||
confidence_threshold=0.8,
|
confidence_threshold=0.8,
|
||||||
max_concurrency=3,
|
max_concurrency=2,
|
||||||
)
|
)
|
||||||
deps = ResearchDeps(client=client)
|
deps = ResearchDeps(client=client)
|
||||||
result = await graph.run(PlanNode(provider=None, model=None), state=state, deps=deps)
|
|
||||||
|
result = await graph.run(
|
||||||
|
PlanNode(provider="openai", model="gpt-4o-mini"),
|
||||||
|
state=state,
|
||||||
|
deps=deps,
|
||||||
|
)
|
||||||
|
|
||||||
report = result.output
|
report = result.output
|
||||||
print(report.title)
|
print(report.title)
|
||||||
print(report.executive_summary)
|
print(report.executive_summary)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Python usage (streamed events):
|
||||||
|
|
||||||
|
```python
|
||||||
|
from haiku.rag.client import HaikuRAG
|
||||||
|
from haiku.rag.research import (
|
||||||
|
PlanNode,
|
||||||
|
ResearchContext,
|
||||||
|
ResearchDeps,
|
||||||
|
ResearchState,
|
||||||
|
build_research_graph,
|
||||||
|
stream_research_graph,
|
||||||
|
)
|
||||||
|
|
||||||
|
async with HaikuRAG(path_to_db) as client:
|
||||||
|
graph = build_research_graph()
|
||||||
|
question = "What are the main drivers and trends of global temperature anomalies since 1990?"
|
||||||
|
state = ResearchState(
|
||||||
|
context=ResearchContext(original_question=question),
|
||||||
|
max_iterations=2,
|
||||||
|
confidence_threshold=0.8,
|
||||||
|
max_concurrency=2,
|
||||||
|
)
|
||||||
|
deps = ResearchDeps(client=client)
|
||||||
|
|
||||||
|
async for event in stream_research_graph(
|
||||||
|
graph,
|
||||||
|
PlanNode(provider="openai", model="gpt-4o-mini"),
|
||||||
|
state,
|
||||||
|
deps,
|
||||||
|
):
|
||||||
|
if event.type == "log":
|
||||||
|
iteration = event.state.iterations if event.state else state.iterations
|
||||||
|
print(f"[{iteration}] {event.message}")
|
||||||
|
elif event.type == "report":
|
||||||
|
print("\nResearch complete!\n")
|
||||||
|
print(event.report.title)
|
||||||
|
print(event.report.executive_summary)
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,8 @@ Flags:
|
||||||
- `--max-concurrency`: number of sub-questions searched in parallel each iteration (default: 3)
|
- `--max-concurrency`: number of sub-questions searched in parallel each iteration (default: 3)
|
||||||
- `--verbose`: show planning, searching previews, evaluation summary, and stop reason
|
- `--verbose`: show planning, searching previews, evaluation summary, and stop reason
|
||||||
|
|
||||||
|
When `--verbose` is set the CLI also consumes the internal research stream, printing every `log` event as agents progress through planning, search, evaluation, and synthesis. If you build your own integration, call `stream_research_graph` to access the same `log`, `report`, and `error` events and render them however you like while the graph is running.
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
Start the MCP server:
|
Start the MCP server:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue