Skip to main content
Integrate Moss semantic search into LangChain using a custom retriever and agent tool. This setup lets you use Moss in standard LangChain RAG pipelines and agentic workflows with sub-10ms retrieval latency.
Note: For complete examples including RAG chains and ReAct agents, see the LangChain cookbook.

Why use Moss with LangChain?

LangChain’s retriever interface is the standard way to plug external knowledge into LLM chains. Moss delivers sub-10ms semantic search that slots directly into this interface, giving your chains and agents fast, accurate retrieval without the latency overhead of traditional vector databases.

Required tools

  • Moss account with project credentials
  • OpenAI API key (for LLM and agent usage)
  • Python 3.11+

Integration guide

1

Installation

2

Environment setup

Create a .env file in your project root.
.env
3

Use as a retriever

The cookbook provides a MossRetriever class that implements LangChain’s BaseRetriever interface. It loads the Moss index once and returns Document objects with metadata and relevance scores.
4

Use as an agent tool

The cookbook also provides a get_moss_tool() function that wraps the retriever as a LangChain Tool, so agents can search the knowledge base autonomously.