Skip to main content

LangChain Ceramic

LangChain integration for Ceramic — a web search API built for LLMs.

Installation

pip install langchain langchain-openai langchain-ceramic

Setup

Generate an API key at platform.ceramic.ai/keys, then export it:

export CERAMIC_API_KEY="your-api-key"

Also set up any additional API keys you need, e.g., OpenAI via

export OPENAI_API_KEY="your-api-key"

Example usage

Tool calling

LangChain agents can use Ceramic search via tool calling to support their response with sources from the web.

Ceramic uses lexical (keyword-based) search. See Best Practices for information on how to use Ceramic Search most effectively. When calling Ceramic search via a tool call, the LLM automatically converts the natural language query into an optimized keyword-based query for search.

from langchain_ceramic import CeramicSearch
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent

# Initialize the Ceramic search tool and retrieve a maximum of five results
ceramic_search = CeramicSearch(max_results=5)

# Initialize the agent with the Ceramic search tool
agent = create_agent(
    model=ChatOpenAI(model="gpt-5.5"), 
    tools=[ceramic_search],
    system_prompt="You are a helpful research assistant. Use web search to find accurate, up-to-date information."
)

# Generate a response using natural language queries
result = agent.invoke(
    {"messages": [{"role": "user", "content": "Tell me about California rental laws."}]}
)
print(result["messages"][-1].content)

RAG pipeline

Use the retriever tool CeramicSearchRetriever to obtain relevant documents for RAG pipelines.

Because Ceramic uses lexical search, we first convert the natural language query into keywords using an LLM before retrieval. The original natural language query is still passed through to the answer prompt.

from langchain_ceramic import CeramicSearchRetriever
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI

# Initialize the LLM and Ceramic Search Retriever
llm = ChatOpenAI(model="gpt-5.5")
retriever = CeramicSearchRetriever(k=5)

# Convert the natural language query to keywords before retrieval
keyword_prompt = PromptTemplate.from_template(
    """
    Rewrite the following question as a 2-8 word keyword query for a lexical search engine.
    
    Rules:
    - Extract specific entities, topics, locations, and dates
    - Replace conversational phrasing with concrete keywords
    - Do not include uninformative words such as articles (the, a, an). Avoid prepositions (on, about, in, for, of, at, by, with) unless they are within established phrases or names (United States of America, Into the Wild).
    - Include relevant synonyms explicitly when terminology is ambiguous
    - Keep word order meaningful (`house cat` and `cat house` return different results)
    - Good keyword query examples:
        - "2026 Super Bowl halftime performer"
        - "climate change effects global warming impact"
        - "beginner investing strategies stocks bonds basics"
    
    Return only the keyword query with no explanation.

    Question: {query}
    """
)
keyword_chain = keyword_prompt | llm | StrOutputParser()

# Format the prompt with the query and retrieved search context
answer_prompt = ChatPromptTemplate.from_template(
    "Answer the query based on the provided context.\n\nQuery: {query}\n\nContext: {context}"
)

# Create the complete chain, which involves keyword_chain and passes the formatted prompt to the LLM
# RunnablePassthrough() preserves the natural language query for the answer prompt
chain = (
    {"query": RunnablePassthrough(), "context": keyword_chain | retriever}
    | answer_prompt
    | llm
    | StrOutputParser()
)

# Generate the response
answer = chain.invoke("What are the latest AI chip export restrictions?")
print(answer)

Each retrieved Document has:

  • page_content: the result description
  • metadata["title"]: page title
  • metadata["url"]: source URL

Async usage

Both CeramicSearchRetriever and CeramicSearch support async:

docs = await retriever.ainvoke("California rental laws")

Parameters

CeramicSearch

Parameter Type Default Description
api_key str | None None Ceramic API key (falls back to CERAMIC_API_KEY env var)
max_results int 5 Maximum number of results to include in the response string

CeramicSearchRetriever

Parameter Type Default Description
api_key str | None None Ceramic API key (falls back to CERAMIC_API_KEY env var)
k int 10 Maximum number of results to return

Metadata

Release files for langchain-ceramic 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-ceramic 0.1.9
File Size Uploaded
langchain_ceramic-0.1.9.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-ceramic 0.1.9
File Interpreter ABI Platform
langchain_ceramic-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / langchain_ceramic-0.1.9.tar.gz

Download URL langchain_ceramic-0.1.9.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fd64cc0844d2d28c0fa5d705cce8c762b29581cc79e0a38b98ee10c1bcfb18b2
BLAKE2b-256 checksum
How to use checksums
8515bfa8bb52144a146c21fcbc3ba2b2704821b89b5c1dd20cad70d7afb16888
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / langchain_ceramic-0.1.9-py3-none-any.whl

Download URL langchain_ceramic-0.1.9-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89407474fbf08c5ddc5e8afbda0b2b9d2f1003829f9484f8b51dae82eaf8ca28
BLAKE2b-256 checksum
How to use checksums
f73c83b7d03870c97fbdbb50a7986bc847722002e5bc03fdbdec9de9609ecbd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page