Copyright | (c) 2025 Tushar Adhatrao |
---|---|
License | MIT |
Maintainer | Tushar Adhatrao <[email protected]> |
Stability | experimental |
Safe Haskell | None |
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:
let oEmbed = defaultOpenAIEmbeddings { apiKey = "api-key" } let p = PdfLoader "homeuserDocumentsTSlangchainSOP.pdf" eDocs <- load p case eDocs of Left err -> error err Right docs -> do eRes <- embedQuery oEmbed Hello print eRes
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 # | |
Defined in Langchain.Embeddings.Ollama Methods embedDocuments :: OllamaEmbeddings -> [Document] -> IO (Either String [[Float]]) Source # embedQuery :: OllamaEmbeddings -> Text -> IO (Either String [Float]) Source # | |
Embeddings OpenAIEmbeddings Source # | |
Defined in Langchain.Embeddings.OpenAI Methods embedDocuments :: OpenAIEmbeddings -> [Document] -> IO (Either String [[Float]]) Source # embedQuery :: OpenAIEmbeddings -> Text -> IO (Either String [Float]) Source # |