LangChain Integration
Overview
The LiquidMetal Python integration package includes a custom LangChain retriever that lets you use SmartBucket within your LangChain applications. This integration enables semantic search capabilities in your LangChain pipelines.
Prerequisites
- Python 3.7 or higher
- LiquidMetal API key
lm-raindrop-integrations
package installed
Installation
pip install lm-raindrop-integrations
Quick Start
Here’s how to use the SmartBucket retriever in your LangChain application:
from lm_raindrop_integrations import LangchainSmartBucketRetriever
# Initialize the retrieverretriever = LangchainSmartBucketRetriever( api_key="your-api-key" # Alternatively, set RAINDROP_API_KEY env variable)
# Search for documentsresults = retriever.invoke("What is machine learning?")
# Process resultsfor doc in results: print(f"Content: {doc.page_content}") print(f"Score: {doc.metadata['score']}") print(f"Source: {doc.metadata['source']}") print("---")
Response Format
The retriever returns LangChain Document objects. Here’s an example response:
# Example response structure[ Document( page_content="Machine learning is a subset of artificial intelligence that enables systems to learn and improve from experience without being explicitly programmed.", metadata={ 'score': 0.89, 'source': 'introduction_to_ml.pdf', 'bucket_id': 'ml_docs_bucket' } ), Document( page_content="Deep learning is a type of machine learning based on artificial neural networks.", metadata={ 'score': 0.76, 'source': 'deep_learning_basics.pdf', 'bucket_id': 'ml_docs_bucket' } )]
Each Document object contains:
page_content
: The matched text contentmetadata
: A dictionary containing:score
: Relevance score (0-1)source
: Original document sourcebucket_id
: ID of the SmartBucket containing the document