Skip to main content
The langchain-nia package provides 20 LangChain-compatible tools that give any LangChain agent full access to Nia — a search and index API that continuously provides context from docs, research papers, datasets, codebases, and more so agents never rely on stale data.
Official LangChain partner integration built with langchain-core and the standard BaseTool / BaseToolkit interfaces. Passes all LangChain standard tests.

Features

Semantic Search

Search across indexed repos, docs, datasets, Slack, and more with natural language queries.

Source Management

Index, list, sync, read, grep, and explore any indexed source directly from your agent.

GitHub Tools

Search code, read files, glob for patterns, and browse file trees in any GitHub repository.

Context Sharing

Save and search conversation context across agents for persistent knowledge sharing.

Installation

pip install langchain-nia

Setup

1. Get Your API Key

Sign up at trynia.ai to get your API key, or run the wizard:
npx nia-wizard@latest

2. Set the Environment Variable

export NIA_API_KEY="nk_..."
Or pass it directly in code:
from langchain_nia import NiaAPIWrapper, NiaToolkit

wrapper = NiaAPIWrapper(nia_api_key="nk_...")
toolkit = NiaToolkit(api_wrapper=wrapper)

Quick Start

Using the Toolkit

The NiaToolkit provides all 20 tools with a shared API client. Toggle tool groups with boolean flags:
from langchain_nia import NiaToolkit

toolkit = NiaToolkit(
    include_search=True,        # 5 search tools
    include_sources=True,       # 7 source management tools
    include_github=True,        # 4 GitHub tools
    include_contexts=True,      # 2 context/memory tools
    include_dependencies=True,  # 2 dependency tools
)

tools = toolkit.get_tools()

Using Individual Tools

from langchain_nia import NiaSearch

tool = NiaSearch()
result = tool.invoke({"query": "how does authentication work?"})

With a LangChain Agent

from langchain_nia import NiaToolkit
from langchain_openai import ChatOpenAI

toolkit = NiaToolkit()
tools = toolkit.get_tools()

llm = ChatOpenAI(model="gpt-4o")
llm_with_tools = llm.bind_tools(tools)

response = llm_with_tools.invoke("Search for React hooks best practices in my indexed repos")

Available Tools

Search (5 tools)

ToolDescription
NiaSearchSemantic search across all indexed repos, docs, and data sources
NiaWebSearchWeb search with category filtering (github, news, research, etc.) and date range
NiaDeepResearchMulti-step comprehensive research with output formatting
NiaUniversalSearchSearch all sources simultaneously with compression options
NiaAdvisorAnalyze code against indexed documentation for recommendations

Source Management (7 tools)

ToolDescription
NiaIndexIndex new sources — repos, docs, papers, datasets, local folders
NiaSourceListList indexed sources with type, status, and query filtering
NiaSourceSubscribeSubscribe to pre-indexed public sources
NiaSourceSyncRe-sync an indexed source to pull latest changes
NiaReadRead files or pages from indexed sources (supports line ranges)
NiaGrepRegex pattern search within indexed sources with context lines
NiaExploreBrowse the file tree structure of any indexed source

GitHub (4 tools)

ToolDescription
NiaGitHubSearchSearch code in GitHub repositories via GitHub Code Search
NiaGitHubReadRead files from GitHub repos with optional line ranges
NiaGitHubGlobFind files matching glob patterns (e.g. **/*.py)
NiaGitHubTreeBrowse the file tree of any GitHub repository

Context & Memory (2 tools)

ToolDescription
NiaContextSaveSave findings, resources, or context with tags for cross-agent sharing
NiaContextSearchSemantic search over previously saved contexts

Dependencies (2 tools)

ToolDescription
NiaDependencySubscribeAuto-subscribe to docs for all dependencies in a manifest file
NiaDependencyAnalyzePreview what would be indexed from a package manifest

Async Support

All 20 tools support both synchronous and asynchronous execution:
import asyncio
from langchain_nia import NiaSearch

tool = NiaSearch()

# Sync
result = tool.invoke({"query": "React hooks"})

# Async
result = asyncio.run(tool.ainvoke({"query": "React hooks"}))


Need Help? Join our Discord community or reach out through app.trynia.ai for support.