Skip to main content

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

Project description

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

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_dewey-0.2.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

langchain_dewey-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file langchain_dewey-0.2.0.tar.gz.

File metadata

  • Download URL: langchain_dewey-0.2.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for langchain_dewey-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f9ee204462edee23b13c00f12c2ae4aeaaabd7e0c83ef7a95e1b10512037dc44
MD5 2424f9112465a83dc80487ba7619ca90
BLAKE2b-256 975a18c77654604cbd553d1a030036c102c11fe88e159c0a575108a74576c913

See more details on using hashes here.

File details

Details for the file langchain_dewey-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_dewey-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90c65fefcfa888f89e9edf4d8bd96292176fa0d362c527dcc46b9eee90418ea
MD5 a2dea44ad36118767983165548117209
BLAKE2b-256 97ed3d1875e38b60e8a33c2015e483f2972e7816ebaa4964d460ec0f0838eb0d

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