langchain-hs-0.0.2.0: Haskell implementation of Langchain
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <[email protected]>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

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

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

Constructors

InMemory 

Fields

Instances

Instances details
(Embeddings m, Show m) => Show (InMemory m) Source # 
Instance details

Defined in Langchain.VectorStore.InMemory

Methods

showsPrec :: Int -> InMemory m -> ShowS #

show :: InMemory m -> String #

showList :: [InMemory m] -> ShowS #

(Embeddings m, Eq m) => Eq (InMemory m) Source # 
Instance details

Defined in Langchain.VectorStore.InMemory

Methods

(==) :: InMemory m -> InMemory m -> Bool #

(/=) :: InMemory m -> InMemory m -> Bool #

Embeddings m => VectorStore (InMemory m) Source # 
Instance details

Defined in Langchain.VectorStore.InMemory

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}

norm :: [Float] -> Float Source #

Calculate Euclidean norm of a vector Example:

>>> norm [3,4]
5.0

dotProduct :: [Float] -> [Float] -> Float Source #

Compute dot product of two vectors Example:

>>> dotProduct [1,2,3] [4,5,6]
32.0

cosineSimilarity :: [Float] -> [Float] -> Float Source #

Calculate cosine similarity between vectors Example:

>>> cosineSimilarity [1,2] [2,4]
1.0