This cookbook demonstrates how to integrate Moss with LangChain.
Moss is a semantic search platform that allows you to build and query high-performance vector indices without managing infrastructure. This integration provides:
- MossRetriever: A LangChain-compatible retriever for semantic search.
- MossSearchTool: A tool for LangChain agents to search your knowledge base.
Ensure you have the required packages installed:
pip install inferedge-moss langchain langchain-openai python-dotenvCreate a .env file with your Moss credentials:
MOSS_PROJECT_ID=your_project_id
MOSS_PROJECT_KEY=your_project_key
MOSS_INDEX_NAME=your_index_name
OPENAI_API_KEY=your_openai_api_keyThe MossRetriever can be used in any LangChain chain.
from moss_langchain import MossRetriever
retriever = MossRetriever(
project_id="your_id",
project_key="your_key",
index_name="your_index",
top_k=3,
alpha=0
)
docs = retriever.invoke("What is the refund policy?")You can also use Moss as a tool for an agent.
from moss_langchain import get_moss_tool
tool = get_moss_tool(
project_id="your_id",
project_key="your_key",
index_name="your_index"
)
# Add to agent tools
tools = [tool]Check out the moss_langchain.ipynb notebook for complete examples including:
- Direct index querying
- Retrieval-Augmented Generation (RAG)
- ReAct Agent with Moss search