For the complete documentation index, see llms.txt. This page is also available as Markdown.
LangChain and LlamaIndex
Use SciSpace as a retriever so an existing RAG application gains scholarly grounding.
Community adapters, not first-party packages
There is no official SciSpace package for either framework. The recipes below use the Python SDK directly, which is stable and versioned. Roughly 30 lines gets you a working retriever, and you keep control of how citations flow through your chain.
LangChain retriever
from typing import List
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from scispace import Scispace
class SciSpaceRetriever(BaseRetriever):
client: Scispace = Scispace()
depth: str = "standard"
max_papers: int = 20
def _get_relevant_documents(self, query: str) -> List[Document]:
search = self.client.searches.create(
query=query, depth=self.depth, max_papers=self.max_papers
).wait()
return [
Document(
page_content=c.quote or "",
metadata={
"source_id": c.source.id,
"title": c.source.title,
"source_type": c.source.type, # paper | document | model
"page": c.locations[0].page if c.locations else None,
"url": c.source.url,
},
)
for c in search.answer.citations
]LlamaIndex
Wrap the same call in a BaseRetriever returning NodeWithScore, carrying the identical metadata
keys. The mapping is what matters, not the framework.
Preserving citations through the chain
This is the whole point of the integration, and the easiest thing to lose.
Keep
source_idandpageon every node. A chain that concatenatespage_contentinto a prompt and discards metadata produces an ungrounded answer with extra steps.Drop or label
source_type == "model"nodes. They carry no quote and no locator.Render citations from metadata, not from the LLM's output. Never let a downstream model invent citation numbers — map them from
source_id.
Cost
Each retriever call is one search: 5 credits at standard. A chain that retrieves on
every turn of a conversation multiplies that — cache by normalized query. See cost-control.
Related
Last updated