Skip to main content

Installation

The SDK is published to PyPI. Install it using pip or uv.
uv add larkup-rag

Initialization

Import the client and initialize it. The client will automatically fall back to LARKUP_RAG_API_URL and LARKUP_RAG_API_KEY environment variables if no arguments are passed. Both synchronous and asynchronous clients are available.
from larkup_rag import LarkupRAGClient, LarkupRAGClientOptions

options = LarkupRAGClientOptions(
    base_url="http://localhost:8080",
    api_key="your-api-key"
)

client = LarkupRAGClient(options)

Basic Usage

Adding a Document

from larkup_rag import Document

doc = Document(
    id="doc-1",
    text="Larkup RAG is a flexible, high-performance RAG pipeline.",
    title="Introduction"
)

response = client.add_document(doc)
print("Document added:", response["success"])

Querying

results = client.query("What is Larkup RAG?", top_k=5)

for hit in results.hits:
    print(f"Score: {hit.score} | Text: {hit.text}")

Integrations

LangChain Python

You can easily wrap the Larkup RAG client into a custom retriever for LangChain Python, allowing you to use it in your chains and agents.
from typing import List
from langchain_core.retrievers import BaseRetriever
from langchain_core.documents import Document
from pydantic import Field
from larkup_rag import LarkupRAGClient

class LarkupRetriever(BaseRetriever):
    client: LarkupRAGClient = Field(default_factory=LarkupRAGClient)
    
    def _get_relevant_documents(self, query: str, *, run_manager=None) -> List[Document]:
        results = self.client.query(query, top_k=5)
        
        # Convert our hits to LangChain Documents
        return [
            Document(page_content=hit.text, metadata={"score": hit.score}) 
            for hit in results.hits
        ]

# Usage:
# retriever = LarkupRetriever()
# docs = retriever.invoke("What is Larkup RAG?")