Copyright | (c) 2025 Tushar Adhatrao |
---|---|
License | MIT |
Maintainer | Tushar Adhatrao <tusharadhatrao@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Langchain.VectorStore.Core
Description
Haskell implementation of LangChain's vector store interface, providing:
- Document storage with vector embeddings
- Similarity-based search capabilities
- Integration with Runnable workflows
Example usage with hypothetical FAISS store:
-- Create vector store instance faissStore :: FAISSStore faissStore = emptyFAISSStore -- Add documents with embeddings docs = [Document "Haskell is functional" mempty, ...] updatedStore <- addDocuments faissStore docs -- Perform similarity search results <- similaritySearch updatedStore "functional programming" 5 -- Returns top 5 relevant documents
Documentation
class VectorStore m where Source #
Vector store abstraction following LangChain's design patterns Implementations should handle document storage, vectorization, and similarity search.
Example instance for an in-memory store:
data InMemoryStore = InMemoryStore { documents :: [Document] , embeddings :: [[Float]] } instance VectorStore InMemoryStore where addDocuments store docs = ... similaritySearch store query k = ...
Methods
addDocuments :: m -> [Document] -> IO (Either String m) Source #
Add documents to the vector store
Example:
>>>
addDocuments myStore [Document "Test content" mempty]
Right (updatedStoreWithNewDocs)
delete :: m -> [Int64] -> IO (Either String m) Source #
Requires document ID tracking to be implemented in store instances.
Example usage (when implemented):
>>>
delete myStore [123]
Right (storeWithoutDoc123)
similaritySearch :: m -> Text -> Int -> IO (Either String [Document]) Source #
Find documents similar to query text Uses embedded vector representations for semantic search.
Example:
>>>
similaritySearch store "Haskell monads" 3
Right [Document "Monads in FP...", ...]
similaritySearchByVector :: m -> [Float] -> Int -> IO (Either String [Document]) Source #
Find documents similar to vector representation For direct vector comparisons without text conversion.
Example:
>>>
similaritySearchByVector store [0.1, 0.3, ...] 5
Right [mostSimilarDoc1, ...]
Instances
Embeddings m => VectorStore (InMemory m) Source # | |
Defined in Langchain.VectorStore.InMemory Methods addDocuments :: InMemory m -> [Document] -> IO (Either String (InMemory m)) Source # delete :: InMemory m -> [Int64] -> IO (Either String (InMemory m)) Source # similaritySearch :: InMemory m -> Text -> Int -> IO (Either String [Document]) Source # similaritySearchByVector :: InMemory m -> [Float] -> Int -> IO (Either String [Document]) Source # |