Copyright | (c) 2025 Tushar Adhatrao |
---|---|
License | MIT |
Maintainer | Tushar Adhatrao <tusharadhatrao@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Langchain.Embeddings.Core
Contents
Description
Haskell implementation of LangChain's embedding model abstraction, providing:
- Document vectorization for semantic search
- Query embedding for similarity comparisons
- Integration with document loading pipelines
Example usage:
-- Hypothetical HuggingFace embedding instance data HuggingFaceEmbeddings = HuggingFaceEmbeddings instance Embeddings HuggingFaceEmbeddings where embedDocuments _ docs = do -- Convert documents to vectors using HuggingFace API return $ Right [[0.1, 0.3, ...], ...] embedQuery _ query = do -- Convert query to vector return $ Right [0.2, 0.4, ...] -- Usage with loaded documents docs <- load (FileLoader "data.txt") case docs of Right documents -> do vectors <- embedDocuments HuggingFaceEmbeddings documents -- Use vectors for semantic search Left err -> print err
Synopsis
- class Embeddings m where
Embedding Interface
class Embeddings m where Source #
Typeclass for embedding models following LangChain's pattern. Converts text/documents into numerical vectors for machine learning tasks.
Implementations should handle:
- Text preprocessing
- API calls to embedding services
- Error handling for failed requests
- Consistent vector dimensionality
Example instance for a test model:
data TestEmbeddings = TestEmbeddings instance Embeddings TestEmbeddings where embedDocuments _ _ = return $ Right [[0.1, 0.2, 0.3]] embedQuery _ _ = return $ Right [0.4, 0.5, 0.6]
Methods
embedDocuments :: m -> [Document] -> IO (Either String [[Float]]) Source #
Convert documents to embedding vectors
Example:
>>>
let doc = Document "Hello world" mempty
>>>
embedDocuments TestEmbeddings [doc]
Right [[0.1, 0.2, 0.3]]
embedQuery :: m -> Text -> IO (Either String [Float]) Source #
Convert query text to embedding vector
Example:
>>>
embedQuery TestEmbeddings "Search query"
Right [0.4, 0.5, 0.6]
Instances
Embeddings OllamaEmbeddings Source # | Ollama implementation of the Example instance usage:
|
Defined in Langchain.Embeddings.Ollama Methods embedDocuments :: OllamaEmbeddings -> [Document] -> IO (Either String [[Float]]) Source # embedQuery :: OllamaEmbeddings -> Text -> IO (Either String [Float]) Source # |