Skip to main content

Eunomia extension for LangChain

Project description

Eunomia extension for LangChain

This package provides an extension of Eunomia for LangChain, allowing you to:

Installation

Install the eunomia-langchain package via pip:

pip install eunomia-langchain

Usage

Document Loader

The EunomiaLoader class is a wrapper around any loader class from LangChain that sends documents to the Eunomia server.

from eunomia_langchain import EunomiaLoader
from langchain_community.document_loaders.csv_loader import CSVLoader

# Create a document loader
loader = CSVLoader("data.csv")

# Wrap the loader with Eunomia
wrapped_loader = EunomiaLoader(loader)

# Load documents and register them with the Eunomia server
docs = wrapped_loader.load(additional_metadata={"group": "financials"})

All loaded documents will be automatically sent to the Eunomia server which will assign an identifier to each document and store their metadata. The identifiers and metadata can then be used to configure or reference policies in the Eunomia server.

Document Retriever

The EunomiaRetriever class wraps any LangChain retriever and filters allowed documents using the Eunomia server.

from eunomia_core import schemas
from eunomia_langchain import EunomiaRetriever
from langchain_community.retrievers import BM25Retriever
from langchain_core.documents import Document

# Create a retriever with some documents
retriever = BM25Retriever.from_documents([
    Document(page_content="foo", metadata={"confidentiality": "public"}),
    Document(page_content="bar", metadata={"confidentiality": "public"}),
    Document(page_content="foo bar", metadata={"confidentiality": "private"}),
])

# Wrap the retriever with Eunomia
wrapped_retriever = EunomiaRetriever(
    retriever=retriever,
    principal=schemas.PrincipalCheck(uri="test-uri"),
)

# Only documents the principal has access to will be returned
docs = wrapped_retriever.invoke("foo")

Documentation

For detailed usage, check out the SDK's documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eunomia_langchain-0.3.9.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eunomia_langchain-0.3.9-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file eunomia_langchain-0.3.9.tar.gz.

File metadata

  • Download URL: eunomia_langchain-0.3.9.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for eunomia_langchain-0.3.9.tar.gz
Algorithm Hash digest
SHA256 01a8251ee224b276a37a1f2449aa9e992374645e90ce0bed7df692c16d0a1d75
MD5 ce79f02530eb4da5022043ecb5b865fc
BLAKE2b-256 2217709670a25cda7b015f2f580b66b4e2748c9ecf07521548c2708d27762c0d

See more details on using hashes here.

File details

Details for the file eunomia_langchain-0.3.9-py3-none-any.whl.

File metadata

File hashes

Hashes for eunomia_langchain-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 60f7ad5d3e51750867a0f903eff4d9cb34824e5c6a77406b521255fd076fc8b5
MD5 6f0d0d02322802edbf24edf69db77a69
BLAKE2b-256 b2f6e9f14aa58e976600284690d5ae61110f06b866fbe10681d5bda64ab56cdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page