Integration details
This notebook illustrates how to integrate Permit.io permissions into LangChain retrievers. We provide two custom retrievers:- PermitSelfQueryRetriever – Uses a self-query approach to parse the user’s natural-language prompt, fetch the user’s permitted resource IDs from Permit, and apply that filter automatically in a vector store search.
- PermitEnsembleRetriever – Combines multiple underlying retrievers (e.g., BM25 + Vector) via LangChain’s EnsembleRetriever, then filters the merged results with Permit.io.
Setup
Install the package with the command:Installation
Environment Variables
- A running Permit PDP. See Permit docs for details on setting up your policy and container.
- A vector store or multiple retrievers that we can wrap.
Instantiation
PermitSelfQueryRetriever
Basic Explanation
- Retrieves permitted document IDs from Permit.
- Uses an LLM to parse your query and build a “structured filter,” ensuring only docs with those permitted IDs are considered.
Basic Usage
PermitEnsembleRetriever
Basic Explanation
- Uses LangChain’s EnsembleRetriever to gather documents from multiple sub-retrievers (e.g., vector-based, BM25, etc.).
- After retrieving documents, it calls filter_objects on Permit to eliminate any docs the user isn’t allowed to see.
Basic Usage
Demo Scripts
For more complete demos, check out the/langchain_permit/examples/demo_scripts
folder:
- demo_self_query.py – Demonstrates PermitSelfQueryRetriever.
- demo_ensemble.py – Demonstrates PermitEnsembleRetriever.