Skip to main content

An integration package connecting Schift and LangChain

This project has been archived.

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

Project description

langchain-schift

LangChain integration for Schift -- vector store with server-side embedding and graph edges.

Installation

pip install langchain-schift

Quick Start

Schift handles embedding server-side, so no Embeddings object is needed:

from langchain_schift import SchiftVectorStore

store = SchiftVectorStore(
    api_key="sk-...",
    bucket="my-bucket",
)

# Add documents (embedded server-side)
store.add_texts(["Contract A supersedes Contract B", "Contract B dated 2024-01"])

# Search
results = store.similarity_search("which contract is newer?", k=3)

Graph-Enhanced Retrieval

Schift supports edges between documents. This is useful for legal citations, document versioning, knowledge graphs, and more:

# Add edges between documents
store.add_edges([
    {"source": "contract-a", "target": "contract-b", "relation": "supersedes"},
    {"source": "clause-1", "target": "contract-a", "relation": "has_child"},
])

# Search with graph expansion -- follows edges from top results
results = store.similarity_search(
    "contract terms",
    k=5,
    graph_expand=True,
    graph_depth=1,
    graph_relations=["supersedes", "has_child"],
)

Supported relation types: contradicts, supersedes, caused_by, is_a, related_to, has_child, follows.

Use with LangChain chains

from langchain_schift import SchiftVectorStore
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

store = SchiftVectorStore(api_key="sk-...", bucket="legal-docs")
retriever = store.as_retriever(search_kwargs={"k": 5})

# Use in a chain
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser

prompt = ChatPromptTemplate.from_template(
    "Answer based on context:\n{context}\n\nQuestion: {question}"
)
llm = ChatOpenAI()

chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

answer = chain.invoke("What are the key contract terms?")

Modes

Mode Use case Embedding
Bucket (recommended) Upload files/texts, Schift handles everything Server-side
Collection Raw vector operations with your own embeddings Client-side or server-side
# Bucket mode (server-side embedding)
store = SchiftVectorStore(api_key="sk-...", bucket="my-bucket")

# Collection mode (bring your own embeddings)
from langchain_openai import OpenAIEmbeddings
store = SchiftVectorStore(
    api_key="sk-...",
    collection="my-collection",
    embedding=OpenAIEmbeddings(),
)

Environment Variables

Set SCHIFT_API_KEY to avoid passing api_key explicitly:

export SCHIFT_API_KEY=sk-...

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

langchain_schift-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

langchain_schift-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file langchain_schift-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_schift-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for langchain_schift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0284ded4644c39258ec61fdbb7bc7bd55ce4ff24505ee83916100becb6ca66b6
MD5 1c0780e2f2da978cd4b4e4a3bffc575f
BLAKE2b-256 ac4e9fe02c006806e3ceb5f15e31cdb745ca24c042df7a8090aea25c96d27d9a

See more details on using hashes here.

File details

Details for the file langchain_schift-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_schift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05ba39947fb5118351123db49a14a161bb61421d8492c8b241785e985a5e7004
MD5 828b7ad32073479609629ee5ea2e9305
BLAKE2b-256 0906262b477f0af0f4dfeb9db91e652148f6f44e22bdf197584e7ad1d323482d

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