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.1.0.tar.gz (8.9 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.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_dewey-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 88123e8f0f8fa1de5cf197d5e4808e4326b11ccbda0233e173e33d75472643cd
MD5 dbdf5484814876425eb7ca232acf3ba8
BLAKE2b-256 0ed29ac635550cd232fcf151b794f26139f839e0e0124f2cfe33975fad860447

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_dewey-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 165ffbe6a645dbcee2877e2434a31e3a59eac30709c536dadf7f18f277f72ab0
MD5 6ce21e98d17c6cd28c0c3df00a8ec91f
BLAKE2b-256 453763892bf4f2f7391756f651700cc93935f74cf9c953ffe4a48300f1f6465b

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