Skip to main content

langchain-dewey

CI

LangChain integration for Dewey — retriever, vector store, and research tool.

Installation

pip install langchain-dewey

Components

DeweyRetriever

Drop-in LangChain retriever backed by Dewey's hybrid semantic + BM25 search.

from langchain_dewey import DeweyRetriever
from langchain_openai import ChatOpenAI
from langchain.chains import RetrievalQA

retriever = DeweyRetriever(
    api_key="dwy_live_...",
    collection_id="3f7a1b2c-...",
    k=8,
)

qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever)
answer = qa.invoke("What are the main findings?")

Each returned Document carries citation metadata:

Field Description
score Relevance score (0–1)
document_id Dewey document ID
filename Original filename
section_id Section ID
section_title Section heading
section_level Heading depth (1 = top-level)

DeweyVectorStore

Full VectorStore implementation. Dewey manages its own embeddings, so the embedding argument is accepted for interface compatibility but unused.

Wrap an existing collection:

from langchain_dewey import DeweyVectorStore

store = DeweyVectorStore(
    api_key="dwy_live_...",
    collection_id="3f7a1b2c-...",
)
docs = store.similarity_search("retrieval augmented generation", k=5)

Build from texts:

store = DeweyVectorStore.from_texts(
    texts=["Neural networks learn via backpropagation.", "..."],
    embedding=None,
    api_key="dwy_live_...",
    collection_name="my-docs",
)
docs = store.similarity_search("how does training work?")

add_texts uploads each string as a .txt document and blocks until Dewey finishes processing them (configurable via poll_interval and poll_timeout).

With LangChain document loaders:

from langchain_community.document_loaders import PyPDFLoader

loader = PyPDFLoader("research_paper.pdf")
pages = loader.load_and_split()

store = DeweyVectorStore.from_documents(
    pages,
    embedding=None,
    api_key="dwy_live_...",
    collection_name="research",
)

create_research_tool

Creates a LangChain @tool that runs a full Dewey research query — searching, reading, and synthesising across multiple documents — for use with agents.

from langchain_dewey import create_research_tool
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate

research = create_research_tool(
    api_key="dwy_live_...",
    collection_id="3f7a1b2c-...",
    depth="balanced",  # "quick" | "balanced" | "deep" | "exhaustive"
)

llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful research assistant."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])
agent = create_openai_tools_agent(llm, [research], prompt)
executor = AgentExecutor(agent=agent, tools=[research])
executor.invoke({"input": "Summarise the key findings across all documents."})

Requirements

  • Python 3.9+
  • meetdewey >= 1.0
  • langchain-core >= 0.3

Development

pip install -e ".[dev]"
pytest

Metadata

Release files for langchain-dewey 0.2.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-dewey 0.2.0
File Size Uploaded
langchain_dewey-0.2.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-dewey 0.2.0
File Interpreter ABI Platform
langchain_dewey-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / langchain_dewey-0.2.0.tar.gz

Download URL langchain_dewey-0.2.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f9ee204462edee23b13c00f12c2ae4aeaaabd7e0c83ef7a95e1b10512037dc44
BLAKE2b-256 checksum
How to use checksums
975a18c77654604cbd553d1a030036c102c11fe88e159c0a575108a74576c913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / langchain_dewey-0.2.0-py3-none-any.whl

Download URL langchain_dewey-0.2.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f90c65fefcfa888f89e9edf4d8bd96292176fa0d362c527dcc46b9eee90418ea
BLAKE2b-256 checksum
How to use checksums
97ed3d1875e38b60e8a33c2015e483f2972e7816ebaa4964d460ec0f0838eb0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

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