### Install langchain-yantrikdb Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Install the package using pip. ```bash pip install langchain-yantrikdb ``` -------------------------------- ### Explain search results with store.explain_search() Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Retrieve search results along with the reasoning behind why they were retrieved. ```python for doc, why in store.explain_search("what is the rate limit?", k=2): print(doc.page_content, why["why_retrieved"]) # ... ['semantically similar (0.93)', 'recent', 'important (decay=0.80)'] ``` -------------------------------- ### Initialize YantrikDBVectorStore and perform similarity search Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Initialize the vector store, add texts, and perform a similarity search. ```python from langchain_yantrikdb import YantrikDBVectorStore store = YantrikDBVectorStore(db_path="./memory.db") store.add_texts([ "The deploy target is eu-west-1", "The database is PostgreSQL 16", ]) docs = store.similarity_search("where do we deploy?", k=1) print(docs[0].page_content) # The deploy target is eu-west-1 retriever = store.as_retriever() # drop into any chain ``` -------------------------------- ### Initialize YantrikDBVectorStore with OpenAIEmbeddings Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Configures the vector store with a specific database path, embedding model, and namespace. The embedding dimension is probed at construction and must remain consistent for the database file's lifetime. ```python from langchain_openai import OpenAIEmbeddings store = YantrikDBVectorStore( db_path="./memory.db", embedding=OpenAIEmbeddings(model="text-embedding-3-small"), namespace="docs", ) ``` -------------------------------- ### Detect contradictions with store.think() Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Add contradictory facts and use the think method to identify potential redundancies. ```python store.add_texts([ "The API rate limit is 100 requests per minute", "The API rate limit is 500 requests per minute", ]) report = store.think() for trigger in report["triggers"]: print(trigger["reason"]) # Two memories are 97% similar and may be redundant (rid_a=..., rid_b=...): # 'The API rate limit is 500 requests per minute' vs # 'The API rate limit is 100 requests per minute' # suggested_action: consolidate_or_forget ``` -------------------------------- ### Configure YantrikDBChatMessageHistory Source: https://github.com/yantrikos/langchain-yantrikdb/blob/main/README.md Use YantrikDBChatMessageHistory with RunnableWithMessageHistory to persist chat sessions. ```python from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_yantrikdb import YantrikDBChatMessageHistory chain_with_history = RunnableWithMessageHistory( chain, lambda session_id: YantrikDBChatMessageHistory( session_id, db_path="./memory.db" ), input_messages_key="input", history_messages_key="history", ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.