Skip to main content

Eunomia SDK for LangChain

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Eunomia SDK for LangChain

This package provides integrations between LangChain and Eunomia, allowing you to:

Installation

Install the eunomia-sdk-langchain package via pip:

pip install eunomia-sdk-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_sdk_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_sdk_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.PrincipalAccess(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_sdk_langchain-0.3.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

eunomia_sdk_langchain-0.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file eunomia_sdk_langchain-0.3.0.tar.gz.

File metadata

File hashes

Hashes for eunomia_sdk_langchain-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8447edec3cb5c0b851a8600f061d94169cf7514df8e321dec16a5ef4ab59314e
MD5 cf188bcab8b44519122aaa467d80c1f4
BLAKE2b-256 d5a57cf015b3dd86533d8606afd88f73ab710718e3e2ece857013d5b3c877500

See more details on using hashes here.

File details

Details for the file eunomia_sdk_langchain-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for eunomia_sdk_langchain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18e92bcf535bba4a42f65a77596bbb47e675e4f41acca6db36d4a70c08c03f38
MD5 3d5478bf9894861bdbedf4d4c459443f
BLAKE2b-256 69be2b1e7ef0cedcd96f479b75972c4dc30837275ced4ed6b9973df80d3bc78a

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