Skip to content

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

Terminal window
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 retriever
retriever = LangchainSmartBucketRetriever(
api_key="your-api-key" # Alternatively, set RAINDROP_API_KEY env variable
)
# Search for documents
results = retriever.invoke("What is machine learning?")
# Process results
for 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 content
  • metadata: A dictionary containing:
    • score: Relevance score (0-1)
    • source: Original document source
    • bucket_id: ID of the SmartBucket containing the document