langchain-perplexity

LangChain integration package for Perplexity AI, providing chat models, embeddings, retrievers, and tools.

SDK
PyPI
v1.4.0
144,512stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
92/100Excellent
Development Activity100
Maintenance100
Community76
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture84
Code Quality85
Innovation78
Learning Curve82

langchain-perplexity is the official LangChain integration for Perplexity AI, the search-grounded large-language-model provider. It exposes Perplexity’s models through LangChain’s standard interfaces so they can be dropped into any chain, agent, or retrieval pipeline built on langchain-core.

The package bundles a ChatPerplexity chat model, embeddings, output parsers, retrievers, and tools that speak Perplexity’s API while conforming to LangChain’s common message, streaming, and tool-calling contracts. This lets developers swap Perplexity in alongside other providers without rewriting application logic.

What You Get

  • A ChatPerplexity chat model implementing LangChain’s BaseChatModel interface with streaming and tool support
  • Perplexity embeddings for use in vector stores and retrieval pipelines
  • Retrievers and tools that expose Perplexity’s search-grounded responses to agents
  • Output parsers for structuring Perplexity responses
  • Full type hints and adherence to LangChain’s standard test suites

Common Use Cases

  • Adding Perplexity’s search-grounded LLM responses to an existing LangChain application
  • Building agents that call Perplexity as a tool for up-to-date, cited answers
  • Swapping Perplexity in as a drop-in provider alongside OpenAI, Anthropic, and others in a chain

Under The Hood

Architecture - The package lives in the LangChain monorepo at libs/partners/perplexity and is a thin adapter layer over the Perplexity API. The bulk of the logic is in langchain_perplexity/chat_models.py (~1700 lines), which defines ChatPerplexity as a subclass of langchain-core’s BaseChatModel, translating LangChain message objects and tool schemas into Perplexity API calls and mapping streamed responses back into LangChain chunk types. Companion modules provide embeddings.py, retrievers.py, tools.py, output_parsers.py, and shared types.py/_utils.py, each conforming to the corresponding langchain-core base class.

Tech Stack - Pure Python (3.10+), built with hatchling. It depends on langchain-core (>=1.4.7) for the abstract interfaces and on the perplexityai client (>=0.34.1) for the underlying HTTP transport, keeping its own footprint minimal.

Code Quality - The package carries an extensive test suite split into unit_tests and integration_tests, including LangChain’s standard conformance tests (test_chat_models_standard, test_embeddings_standard) plus secrets, imports, tools, and output-parser tests. It ships py.typed and is marked Production/Stable, and the standardized test harness ensures behavior stays aligned with the wider LangChain ecosystem.

API Design - Because it implements LangChain’s common interfaces, the developer experience is essentially identical to any other LangChain provider: instantiate ChatPerplexity, pass it into a chain or agent, and streaming, tool calling, and structured output all work through the same contracts. This consistency is the package’s main ergonomic strength — no Perplexity-specific glue code is required in application logic.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search