from langchain_core.documents import Document from langchain_core.embeddings import Embeddings from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableLambda, RunnablePassthrough from langchain_core.vectorstores import InMemoryVectorStore class KeywordEmbeddings(Embeddings): vocabulary = ("checkout", "billing", "password") def _embed(self, text: str) -> list[float]: lower_text = text.lower() return [1.0 if term in lower_text else 0.0 for term in self.vocabulary] def embed_documents(self, texts: list[str]) -> list[list[float]]: return [self._embed(text) for text in texts] def embed_query(self, text: str) -> list[float]: return self._embed(text)