Copyright | (c) 2025 Tushar Adhatrao |
---|---|
License | MIT |
Maintainer | Tushar Adhatrao <[email protected]> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Langchain.VectorStore.InMemory
Description
In-memory vector store implementation following LangChain's patterns, supporting:
- Document storage with embeddings
- Cosine similarity search
- Integration with embedding models
Example usage:
-- Create store with Ollama embeddings ollamaEmb = OllamaEmbeddings "nomic-embed" Nothing Nothing inMem = emptyInMemoryVectorStore ollamaEmb -- Add documents docs = [Document "Hello World" mempty, Document "Haskell is functional" mempty] updatedStore <- addDocuments inMem docs -- Perform similarity search results <- similaritySearch updatedStore "functional programming" 1 -- Right [Document "Haskell is functional"...]
Synopsis
- data Embeddings m => InMemory m = InMemory {}
- fromDocuments :: Embeddings m => m -> [Document] -> IO (Either String (InMemory m))
- emptyInMemoryVectorStore :: Embeddings m => m -> InMemory m
- norm :: [Float] -> Float
- dotProduct :: [Float] -> [Float] -> Float
- cosineSimilarity :: [Float] -> [Float] -> Float
Documentation
data Embeddings m => InMemory m Source #
In-memory vector store implementation Stores documents with:
- Embedding model reference
- Map of document IDs to (Document, embedding) pairs
Instances
(Embeddings m, Show m) => Show (InMemory m) Source # | |
(Embeddings m, Eq m) => Eq (InMemory m) Source # | |
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 # |
fromDocuments :: Embeddings m => m -> [Document] -> IO (Either String (InMemory m)) Source #
Initialize store from documents using embeddings Example:
>>>
fromDocuments ollamaEmb [Document "Test" mempty]
Right (InMemory {_store = ...})
emptyInMemoryVectorStore :: Embeddings m => m -> InMemory m Source #
Create empty in-memory store with embedding model Example:
>>>
emptyInMemoryVectorStore ollamaEmb
InMemory {_embeddingModel = ..., _store = empty}