Find Full-Text Evidence with Sciverse
RAGRetrievalBeginner

Find Full-Text Evidence with Sciverse

Start from a retrieved snippet, locate the source passage, and read fuller context for citation

Scenario
An agent has found relevant snippets through agentic-search, but needs more surrounding context to verify a claim or create an accurate citation.
Estimated calls
~3-8 API calls
Tools
agentic-searchcontent
Pipeline
agentic-search→ doc_id + offset→ content(offset, limit)→ 全文证据

Input example

Input from search result:
doc_id="paper_xxx"
offset=12480
Need: read the source paragraph and surrounding context.

Output example

Evidence context:
"...the model significantly improves contact prediction..."

Source: doc_id=paper_xxx, offset=12480, next_offset=14480, more=true

Agent Prompt example

You are a source verification assistant. Given doc_id and offset, call content to read the source text. Extract only the evidence relevant to the claim and keep traceable source metadata.

Implementation steps

Step 1: Set up the environment

Configure API token and HTTP client

!pip install httpx
import os
os.environ["SCIVERSE_API_TOKEN"] = "sv-your-token-here"  # 替换为你的真实值

Step 2: Read full context

Call content with doc_id, offset, and limit to read the source context

import os
import asyncio
import httpx

BASE = "https://api.sciverse.space"
TOKEN = os.environ["SCIVERSE_API_TOKEN"]
HEADERS = {"Authorization": f"Bearer {TOKEN}"}

async def get_fulltext(doc_id: str, offset: int = 0, limit: int = 2000):
    """读取文档原文。返回 {text, next_offset, more}"""
    async with httpx.AsyncClient(timeout=30) as client:
        resp = await client.get(
            f"{BASE}/content",
            headers=HEADERS,
            params={"doc_id": doc_id, "offset": offset, "limit": limit}
        )
        resp.raise_for_status()
        return resp.json()

async def find_top_hit(query: str) -> dict:
    """Use agentic-search to get a real hit for the content example."""
    async with httpx.AsyncClient(timeout=30) as client:
        resp = await client.post(
            f"{BASE}/agentic-search",
            headers=HEADERS,
            json={"query": query, "top_k": 3},
        )
        resp.raise_for_status()
        hits = (resp.json().get("hits") or [])
        if not hits:
            raise ValueError(f"No papers found for query: {query}")
        return hits[0]

async def main():
    hit = await find_top_hit("AlphaFold2 protein structure prediction")

    # 向前偏移 300 字符以获取前文语境
    start = max(0, hit.get("offset", 0) - 300)
    result = await get_fulltext(hit["doc_id"], offset=start, limit=2000)

    print(f"Text length: {len(result['text'])} chars")
    print(f"Has more: {result['more']}")
    if result.get("next_offset"):
        print(f"Next offset: {result['next_offset']}")
    print(f"\
Content preview:\
{result['text'][:300]}...")
    return hit, result

hit, result = await main()

Step 3: Read iteratively when needed

Follow next_offset while more=true to read additional text

async def read_full_document(doc_id: str, max_chars: int = 16000):
    """循环读取直到全文或达到字符上限"""
    full_text = ""
    offset = 0
    while len(full_text) < max_chars:
        result = await get_fulltext(doc_id, offset=offset, limit=4000)
        full_text += result["text"]
        if not result.get("more"):
            break
        offset = result["next_offset"]
    return full_text

async def main():
    # 使用上一步 agentic-search 返回的真实 hit
    text = await read_full_document(hit["doc_id"], max_chars=16000)
    print(f"Total document length: {len(text)} chars")

await main()

Notes

  • offset is the key anchor for traceability.
  • Use a moderate limit first, then read more only when needed.
  • Do not assume the first chunk contains the full argument.
  • Store next_offset and more if the agent may continue reading later.
  • When quoting, preserve exact source wording.

FAQ

什么时候需要读取全文上下文?

当检索片段不足以判断证据是否支持 claim 时,需要用 content 读取原文上下文。

输出证据时要保留什么?

至少保留 doc_id、offset、原文 quote、标题和年份。

content API 的作用是什么?

它根据 doc_id 和 offset 返回论文全文片段,用于核验语义证据。

如何避免断章取义?

应读取 quote 前后上下文,并在输出中说明证据支持范围。

Next steps

Need an API key?

Create one in Console > Tokens.The same API key works for enabled Sciverse, DianShi, and Skills capabilities, with starter quota available according to account permissions.

Open console