LangChain integration
Learn how to integrate Rememberizer as a LangChain retriever to provide your LangChain application with access to powerful vector database search.
Rememberizer integrates with LangChain through the RememberizerRetriever
class, allowing you to easily incorporate Rememberizer's semantic search capabilities into your LangChain-powered applications. This guide explains how to set up and use this integration to build advanced LLM applications with access to your knowledge base.
Introduction
LangChain is a popular framework for building applications with large language models (LLMs). By integrating Rememberizer with LangChain, you can:
Use your Rememberizer knowledge base in RAG (Retrieval Augmented Generation) applications
Create chatbots with access to your documents and data
Build question-answering systems that leverage your knowledge
Develop agents that can search and reason over your information
The integration is available in the langchain_community.retrievers
module.
Getting Started
Prerequisites
Before you begin, you need:
A Rememberizer account with Common Knowledge created
An API key for accessing your Common Knowledge
Python environment with LangChain installed
For detailed instructions on creating Common Knowledge and generating an API key, see Registering and Using API Keys.
Installation
Install the required packages:
If you plan to use OpenAI models (as shown in examples below):
Authentication Setup
There are two ways to authenticate the RememberizerRetriever
:
Environment Variable: Set the
REMEMBERIZER_API_KEY
environment variableDirect Parameter: Pass the API key directly when initializing the retriever
Configuration Options
The RememberizerRetriever
class accepts these parameters:
top_k_results
int
10
Number of documents to return from search
rememberizer_api_key
str
None
API key for authentication (optional if set as environment variable)
Behind the scenes, the retriever makes API calls to Rememberizer's search endpoint with additional configurable parameters:
prev_chunks
Number of chunks before the matched chunk to include (default: 2)
next_chunks
Number of chunks after the matched chunk to include (default: 2)
return_full_content
Whether to return full document content (default: true)
Basic Usage
Here's a simple example of retrieving documents from Rememberizer using LangChain:
Understanding Document Structure
Each document returned by the retriever has:
page_content
: The text content of the matched document chunkmetadata
: Additional information about the document
Example of metadata structure:
Advanced Examples
Building a RAG Question-Answering System
This example creates a question-answering system that retrieves information from Rememberizer and uses GPT-3.5 to formulate answers:
Building a Conversational Agent with Memory
This example creates a conversational agent that can maintain conversation history:
Best Practices
Optimizing Retrieval Performance
Be specific with queries: More specific queries usually yield better results
Adjust
top_k_results
: Start with 3-5 results and adjust based on application needsUse context windows: The retriever automatically includes context around matched chunks
Security Considerations
Protect your API key: Store it securely using environment variables or secret management tools
Create dedicated keys: Create separate API keys for different applications
Rotate keys regularly: Periodically generate new keys and phase out old ones
Integration Patterns
Pre-retrieval processing: Consider preprocessing user queries to improve search relevance
Post-retrieval filtering: Filter or rank retrieved documents before passing to the LLM
Hybrid search: Combine Rememberizer with other retrievers using
EnsembleRetriever
Troubleshooting
Common Issues
Authentication errors: Verify your API key is correct and properly configured
No results returned: Ensure your Common Knowledge contains relevant information
Rate limiting: Be mindful of API rate limits for high-volume applications
Debug Tips
Set the LangChain debug mode to see detailed API calls:
Examine raw search results before passing to LLM to identify retrieval issues
Related Resources
LangChain Retriever conceptual guide
LangChain Retriever how-to guides
Rememberizer API Documentation
Vector Stores in Rememberizer
Creating a Rememberizer GPT - An alternative approach for AI integration
Last updated