Skip to main content

An integration package connecting LambdaDB and LangChain

Project description

langchain-lambdadb

This package contains the LangChain integration with LambdaDB vector store.

Installation

pip install -U langchain-lambdadb

Prerequisites

Before using this integration, you need to:

  1. Create a collection in LambdaDB with proper vector and text indexes
  2. Have your LambdaDB credentials ready

Creating a Collection

Create a collection in LambdaDB with the required indexes:

from lambdadb import LambdaDB, models

client = LambdaDB(
    server_url="<your-project-url>",
    project_api_key="<your-project-api-key>"

)

# Create collection with vector and text indexes
client.collections.create(
    collection_name="my_collection",
    index_configs={
        "vector": {
            "type": models.TypeVector.VECTOR,
            "dimensions": 1536,  # Match your embedding dimensions
            "similarity": models.Similarity.COSINE
        },
        "text": {
            "type": models.TypeText.TEXT,
            "analyzers": [models.Analyzer.ENGLISH]
        }
    }
)

Quick Start

import os
from lambdadb import LambdaDB
from langchain_lambdadb import LambdaDBVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document

# Set up LambdaDB client
client = LambdaDB(
    server_url=os.getenv("LAMBDADB_PROJECT_URL"),
    project_api_key=os.getenv("LAMBDADB_PROJECT_API_KEY")
)

# Connect to existing collection
vector_store = LambdaDBVectorStore(
    client=client,
    collection_name="my_collection",  # Must be an existing collection
    embedding=OpenAIEmbeddings()
)

# Add documents
documents = [
    Document(page_content="LambdaDB is a vector database", metadata={"source": "docs"}),
    Document(page_content="LangChain integrates with LambdaDB", metadata={"source": "docs"}),
]
vector_store.add_documents(documents)

# Search for similar documents
results = vector_store.similarity_search("What is LambdaDB?", k=2)
for doc in results:
    print(f"Content: {doc.page_content}")
    print(f"Metadata: {doc.metadata}")

Configuration

Set the following environment variables:

export LAMBDADB_PROJECT_URL="<your-project-url>"
export LAMBDADB_PROJECT_API_KEY="<your-project-api-key>"

Vector Store Features

The LambdaDBVectorStore supports:

  • Document Operations: Add, update, and delete documents
  • Similarity Search: Find similar documents using vector search
  • Metadata Filtering: Filter search results by document metadata
  • Batch Operations: Efficient bulk document processing
  • Async Support: Full async/await support for all operations

Advanced Usage

Similarity Search with Scores

# Get similarity scores with results
results_with_scores = vector_store.similarity_search_with_score(
    query="vector database features",
    k=3
)

for doc, score in results_with_scores:
    print(f"Score: {score:.4f}")
    print(f"Content: {doc.page_content}")

Metadata Filtering

# Search with metadata filters
filtered_results = vector_store.similarity_search(
    query="database",
    k=5,
    filter={"source": "documentation"}
)

Using as a Retriever

# Use as a retriever for RAG applications
retriever = vector_store.as_retriever(
    search_type="similarity",
    search_kwargs={"k": 4}
)

relevant_docs = retriever.invoke("How does LambdaDB work?")

Development

For development and testing:

# Clone the repository
git clone <repository-url>
cd langchain-lambdadb

# Install with development dependencies
poetry install --with test,lint

# Run tests with mock data
make test

# Run integration tests with real LambdaDB (requires credentials)
export LAMBDADB_PROJECT_URL="<your-project-url>"
export LAMBDADB_PROJECT_API_KEY="<your-project-api-key>"
# Optional: Use existing collection instead of creating test collections
export LAMBDADB_COLLECTION_NAME="your-test-collection"
make integration_tests

# Lint and format code
make lint
make format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_lambdadb-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_lambdadb-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_lambdadb-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_lambdadb-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.9.25 Linux/6.11.0-1018-azure

File hashes

Hashes for langchain_lambdadb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91a27c3eb73470e46d57ddbd8c55f44d3d6db85bc9e3fccecb2e080cbaac9046
MD5 1e2671914a38c478f249a689d7f543f5
BLAKE2b-256 ff79551388ed7886d43df771cabffa091a49e3ba3cc7e7d5dbb17be743566a41

See more details on using hashes here.

File details

Details for the file langchain_lambdadb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_lambdadb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.9.25 Linux/6.11.0-1018-azure

File hashes

Hashes for langchain_lambdadb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d79ffd12a6ac52f8a2f4ddc9f814c323863a40c7b5c94e58c3add34e817ed2cf
MD5 40c66357b940121a33ca17bffca4b89f
BLAKE2b-256 185731969dccb7b58fb550917773209e060a3b1cc6ea78ccaab15d9788904126

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page