LangChain Integration
Overview
Raindrop provides LangChain integrations for Python and TypeScript that enable you to use SmartBuckets as retrievers in your LangChain applications. The retrievers perform semantic search (chunk_search
) across documents stored in your SmartBuckets and return results as LangChain Document objects.
Installation
For Python applications, install the integration package using pip. The package requires Python 3.8 or higher and includes all necessary dependencies for LangChain compatibility:
pip install lm-raindrop-integrations
The Python package includes optional dependencies for LangChain. If you haven’t already installed LangChain in your project, the package will automatically include the required LangChain core components. For production applications, you may want to explicitly install LangChain with your preferred version:
pip install lm-raindrop-integrations langchain
For TypeScript and JavaScript applications, install the integration package using npm. The package requires Node.js 16 or higher and includes TypeScript declarations for full type safety:
npm install @liquidmetal-ai/lm-raindrop-integrations
You can also use yarn or pnpm as your package manager:
yarn add @liquidmetal-ai/lm-raindrop-integrations# orpnpm add @liquidmetal-ai/lm-raindrop-integrations
The TypeScript package includes all necessary LangChain dependencies and provides full TypeScript support with comprehensive type definitions for all methods and return values.
API Key Configuration
Both implementations support multiple methods for providing your LiquidMetal API key. The most secure approach is to use environment variables, which keeps sensitive credentials out of your source code. Set the RAINDROP_API_KEY
environment variable with your API key:
export RAINDROP_API_KEY="your-api-key-here"
Alternatively, you can provide the API key directly when initializing the retriever, though this approach should be used carefully in production environments. You can obtain an API key by signing up at raindrop.run and following the onboarding process to create your first SmartBucket.
Basic Usage
The fundamental usage pattern for both Python and TypeScript implementations follows the same conceptual approach: initialize a retriever with your bucket name and API key, then use the invoke
method to perform searches. The retrievers handle all the complexity of API communication and result formatting behind the scenes.
Here’s a complete example showing how to use the Python retriever in a typical application:
from lm_raindrop_integrations import LangchainSmartBucketRetrieverimport os
# Initialize the retriever with environment variable for API keyretriever = LangchainSmartBucketRetriever( bucket_name="my-knowledge-base" # API key read from RAINDROP_API_KEY env var)
# Or provide API key explicitlyretriever = LangchainSmartBucketRetriever( api_key="your-api-key", bucket_name="my-knowledge-base")
# Perform a semantic searchresults = retriever.invoke("What are the best practices for machine learning?")
# Process and display resultsfor i, doc in enumerate(results, 1): print(f"Result {i}:") print(f"Content: {doc.page_content[:200]}...") print(f"Relevance Score: {doc.metadata['score']:.3f}") print(f"Source: {doc.metadata['source']['object_name']}") print(f"Chunk ID: {doc.metadata['chunk_signature']}") print("-" * 50)
Here’s how to use the TypeScript retriever:
import { LangchainSmartBucketRetriever } from '@liquidmetal-ai/lm-raindrop-integrations';
// Initialize the retriever with environment variable for API keyconst retriever = new LangchainSmartBucketRetriever({ bucketName: "my-knowledge-base" // API key read from RAINDROP_API_KEY env var});
// Or provide API key explicitlyconst retrieverWithKey = new LangchainSmartBucketRetriever({ bucketName: "my-knowledge-base", apiKey: "your-api-key"});
// Perform a semantic searchconst results = await retriever.invoke("What are the best practices for machine learning?");
// Process and display results with full TypeScript supportresults.forEach((doc, index) => { console.log(`Result ${index + 1}:`); console.log(`Content: ${doc.pageContent.substring(0, 200)}...`); console.log(`Relevance Score: ${doc.metadata.score.toFixed(3)}`); console.log(`Source: ${doc.metadata.source?.object}`); console.log(`Chunk ID: ${doc.metadata.chunkSignature}`); console.log("-".repeat(50));});
Both implementations return results in the same conceptual format, though they follow language-specific conventions for property naming. The Python version uses snake_case following Python conventions, while the TypeScript version uses camelCase following JavaScript conventions.
Response Format
Returns a list of Document
objects:
# 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. It involves algorithms that can identify patterns in data and make predictions or decisions based on those patterns.", metadata={ 'chunk_signature': 'sha256:abc123def456...', 'payload_signature': 'sha256:789xyz012...', 'score': 0.89, 'type': 'text/plain', 'source': { 'object_name': 'ml_fundamentals.pdf', 'bucket_name': 'ai_knowledge_base', 'application_name': 'documentation_system', 'module_id': 'docs_module_v1', 'application_version_id': '01JBQX9K7M3P2N4R5S6T7V8W9X', 'source_raw': { /* full source object */ } } } ), Document( page_content="Deep learning represents a specialized subset of machine learning that uses artificial neural networks with multiple layers to model and understand complex patterns in data.", metadata={ 'chunk_signature': 'sha256:def789ghi012...', 'payload_signature': 'sha256:345abc678...', 'score': 0.76, 'type': 'text/plain', 'source': { 'object_name': 'neural_networks_guide.pdf', 'bucket_name': 'ai_knowledge_base', 'application_name': 'documentation_system', 'module_id': 'docs_module_v1', 'application_version_id': '01JBQX9K7M3P2N4R5S6T7V8W9X', 'source_raw': { /* full source object */ } } } )]
Returns Document
objects with camelCase properties:
// Example response structure[ { pageContent: "Machine learning is a subset of artificial intelligence that enables systems to learn and improve from experience without being explicitly programmed. It involves algorithms that can identify patterns in data and make predictions or decisions based on those patterns.", metadata: { chunkSignature: "sha256:abc123def456...", payloadSignature: "sha256:789xyz012...", score: 0.89, type: "text/plain", source: { object: "ml_fundamentals.pdf", bucket: { name: "ai_knowledge_base", moduleId: "docs_module_v1", applicationName: "documentation_system", applicationVersionId: "01JBQX9K7M3P2N4R5S6T7V8W9X" }, source_raw: { /* full source object */ } } } }, { pageContent: "Deep learning represents a specialized subset of machine learning that uses artificial neural networks with multiple layers to model and understand complex patterns in data.", metadata: { chunkSignature: "sha256:def789ghi012...", payloadSignature: "sha256:345abc678...", score: 0.76, type: "text/plain", source: { object: "neural_networks_guide.pdf", bucket: { name: "ai_knowledge_base", moduleId: "docs_module_v1", applicationName: "documentation_system", applicationVersionId: "01JBQX9K7M3P2N4R5S6T7V8W9X" }, source_raw: { /* full source object */ } } } }]
Metadata Fields
chunk_signature
/chunkSignature
: Hash identifying the text chunkscore
: Relevance score (0-1, higher = more relevant)source
: Document source information including bucket and application metadatapayload_signature
/payloadSignature
: Hash identifying the original payloadtype
: Content type of the source document