Copyright | (c) 2025 Tushar Adhatrao |
---|---|
License | MIT |
Maintainer | Tushar Adhatrao <[email protected]> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
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
- class Retriever a where
- newtype VectorStore a => VectorStoreRetriever a = VectorStoreRetriever {
- vs :: a
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
VectorStore a => Retriever (VectorStoreRetriever a) Source # | Runnable interface for vector store retrievers Allows integration with LangChain workflows and expressions. Example:
|
Defined in Langchain.Retriever.Core Methods _get_relevant_documents :: VectorStoreRetriever a -> Text -> IO (Either String [Document]) Source # | |
(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:
|
Defined in Langchain.Retriever.MultiQueryRetriever Methods _get_relevant_documents :: MultiQueryRetriever a m -> Text -> IO (Either String [Document]) Source # |
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
|