langchain-hs-0.0.2.0: Haskell implementation of Langchain
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <[email protected]>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Langchain.Retriever.Core

Description

Haskell implementation of LangChain's retrieval abstraction, providing:

  • Document retrieval based on semantic similarity
  • Integration with vector stores
  • Runnable interface for workflow composition

Example usage:

-- Hypothetical vector store instance
vectorStore :: MyVectorStore
vectorStore = ...

-- Create retriever
retriever :: VectorStoreRetriever MyVectorStore
retriever = VectorStoreRetriever vectorStore

-- Retrieve relevant documents
docs <- invoke retriever "Haskell programming"
-- Right [Document {pageContent = "...", ...}, ...]
Synopsis

Documentation

class Retriever a where Source #

Typeclass for document retrieval systems Implementations should return documents relevant to a given query.

Example instance for a custom retriever:

data CustomRetriever = CustomRetriever

instance Retriever CustomRetriever where
  _get_relevant_documents _ query = do
    -- Custom retrieval logic
    return $ Right [Document ("Result for: " <> query) mempty]

Methods

_get_relevant_documents :: a -> Text -> IO (Either String [Document]) Source #

Retrieve documents relevant to the query

Example:

>>> _get_relevant_documents (VectorStoreRetriever myStore) "AI"
Right [Document "AI definition...", ...]

Instances

Instances details
VectorStore a => Retriever (VectorStoreRetriever a) Source #

Runnable interface for vector store retrievers Allows integration with LangChain workflows and expressions.

Example:

>>> invoke (VectorStoreRetriever store) "Quantum computing"
Right [Document "Quantum theory...", ...]
Instance details

Defined in Langchain.Retriever.Core

(Retriever a, LLM m) => Retriever (MultiQueryRetriever a m) Source #

Retriever instance implementation 1. Generates multiple queries using LLM 2. Retrieves documents for each query 3. Combines and deduplicates results

Example retrieval:

>>> _get_relevant_documents mqRetriever "Haskell"
Right [Document "Haskell is...", Document "Functional programming...", ...]
Instance details

Defined in Langchain.Retriever.MultiQueryRetriever

newtype VectorStore a => VectorStoreRetriever a Source #

Vector store-backed retriever implementation Wraps any VectorStore instance to provide similarity-based retrieval.

Example usage:

-- Using a hypothetical FAISS vector store
faissStore :: FAISSStore
faissStore = ...

-- Create vector store retriever
vsRetriever = VectorStoreRetriever faissStore

-- Get similar documents
docs <- _get_relevant_documents vsRetriever "machine learning"
-- Returns top 5 relevant documents by default

Constructors

VectorStoreRetriever 

Fields

Instances

Instances details
(VectorStore a, Show a) => Show (VectorStoreRetriever a) Source # 
Instance details

Defined in Langchain.Retriever.Core

Eq a => Eq (VectorStoreRetriever a) Source # 
Instance details

Defined in Langchain.Retriever.Core

VectorStore a => Retriever (VectorStoreRetriever a) Source #

Runnable interface for vector store retrievers Allows integration with LangChain workflows and expressions.

Example:

>>> invoke (VectorStoreRetriever store) "Quantum computing"
Right [Document "Quantum theory...", ...]
Instance details

Defined in Langchain.Retriever.Core

VectorStore a => Runnable (VectorStoreRetriever a) Source #

Runnable interface for vector store retrievers Allows integration with LangChain workflows and expressions.

Example:

>>> invoke (VectorStoreRetriever store) "Quantum computing"
Right [Document "Quantum theory...", ...]
Instance details

Defined in Langchain.Retriever.Core

type RunnableInput (VectorStoreRetriever a) Source # 
Instance details

Defined in Langchain.Retriever.Core

type RunnableOutput (VectorStoreRetriever a) Source # 
Instance details

Defined in Langchain.Retriever.Core