Skip to main content

Moss LangChain Cookbook

This cookbook demonstrates how to integrate Moss with LangChain.

Overview

Moss is a semantic search platform that allows you to build and query high-performance vector indices without managing infrastructure. This integration provides:

  1. MossRetriever: A LangChain-compatible retriever for semantic search.
  2. MossSearchTool: A tool for LangChain agents to search your knowledge base.

Installation

Ensure you have the required packages installed:

pip install inferedge-moss langchain langchain-openai python-dotenv

Setup

Create 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_key

Usage

Using the Retriever

The 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?")

Using the Agent Tool

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]

Examples

Check out the moss_langchain.ipynb notebook for complete examples including:

  • Direct index querying
  • Retrieval-Augmented Generation (RAG)
  • ReAct Agent with Moss search

Release files for langchain-moss 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-moss 0.1.0
File Size Uploaded
langchain_moss-0.1.0.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-moss 0.1.0
File Interpreter ABI Platform
langchain_moss-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.2 kB

Release files / langchain_moss-0.1.0.tar.gz

Download URL langchain_moss-0.1.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3815fae401aa31c0711864e11c6f81e590ae02960d355003b08d6403e16742cb
BLAKE2b-256 checksum
How to use checksums
b0ce4b277aff2e22f6e2faadbc947617f2d36dbc818ff0910517d655ce665cd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / langchain_moss-0.1.0-py3-none-any.whl

Download URL langchain_moss-0.1.0-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7336d32e30b6bb0b1cc84861aa1634f1d573c3d41a8e6a0b10338afdc9720b8b
BLAKE2b-256 checksum
How to use checksums
9ba592106569cb70205229e9beed9318e04765ed9f6c9a91067ab39159d64753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page