An integration package connecting Keiro and LangChain
Project description
langchain-keiro
Official LangChain integration for the Keiro deep search API with embeddings.
All components use deep mode with embeddings enabled — no configuration needed. Every request returns full content plus 768-dimensional embedding vectors (configurable to 384/512/1024 via Matryoshka).
Installation
pip install langchain-keiro
Quick Start
Retriever
Use Keiro as a LangChain retriever for RAG pipelines:
from langchain_keiro.retrievers import KeiroRetriever
retriever = KeiroRetriever(
keiro_api_key="keiro_...",
max_results=3,
)
# Sync
docs = retriever.invoke("What is artificial intelligence?")
# Async
docs = await retriever.ainvoke("What is artificial intelligence?")
# Each doc includes embeddings in metadata:
# doc.metadata["query_embedding"] — 768-dim vector for the query
# doc.metadata["chunk_embeddings"] — per-chunk embeddings with text
# doc.metadata["tldr"], ["tags"], ["entities"], etc.
# Use in a RAG chain
from langchain_openai import ChatOpenAI
from langchain.chains import create_retrieval_chain
llm = ChatOpenAI(model="gpt-4")
chain = create_retrieval_chain(retriever, llm)
response = chain.invoke({"input": "What is AI?"})
Embeddings
Generate embedding vectors directly:
from langchain_keiro.embeddings import KeiroEmbeddings
embeddings = KeiroEmbeddings(
keiro_api_key="keiro_...",
dimensions=768, # Matryoshka: 384, 512, 768, or 1024
)
# Single query
vec = embeddings.embed_query("What is AI?")
# vec is a list of 768 floats
# Batch documents
vecs = embeddings.embed_documents(["doc 1", "doc 2", "doc 3"])
# Async
vec = await embeddings.aembed_query("What is AI?")
vecs = await embeddings.aembed_documents(["doc 1", "doc 2"])
Tool (for Agents)
Use Keiro as a tool in LangChain agents:
from langchain_keiro.tools import KeiroSearchTool
tool = KeiroSearchTool(keiro_api_key="keiro_...")
# Direct invocation
result = tool.invoke({"query": "latest AI research"})
# With an agent
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a research assistant. Use the keiro_search tool to find information."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, [tool], prompt)
agent_executor = AgentExecutor(agent=agent, tools=[tool])
response = agent_executor.invoke({"input": "What are the latest AI trends?"})
Configuration
KeiroRetriever
| Parameter | Type | Default | Description |
|---|---|---|---|
keiro_api_key |
SecretStr |
required | Your Keiro API key |
base_url |
str |
https://kierolabs.space/api |
API base URL |
max_results |
int |
3 |
Number of results (1-5) |
embedding_dimensions |
int |
768 |
Vector dimensions (384, 512, 768, 1024) |
Always uses mode="deep" with embeddings.enabled=true.
KeiroEmbeddings
| Parameter | Type | Default | Description |
|---|---|---|---|
keiro_api_key |
SecretStr |
required | Your Keiro API key |
base_url |
str |
https://kierolabs.space/api |
API base URL |
model |
str |
"pplx-embed-v1-0.6b" |
Embedding model identifier |
dimensions |
int |
768 |
Vector dimensions (384, 512, 768, 1024) |
KeiroSearchTool
| Parameter | Type | Default | Description |
|---|---|---|---|
keiro_api_key |
SecretStr |
required | Your Keiro API key |
base_url |
str |
https://kierolabs.space/api |
API base URL |
Always uses mode="deep" with embeddings.enabled=true.
Embedding Dimensions (Matryoshka)
The Keiro API supports Matryoshka embedding dimensions, allowing you to trade off vector size for precision:
- 384: Smallest, fastest, least precise
- 512: Good balance for lightweight use
- 768 (default): Standard precision
- 1024: Maximum precision
Response Enrichment
The deep mode response includes rich metadata beyond just content:
| Field | Description |
|---|---|
query_embedding |
768-dim embedding vector for the search query |
chunk_embeddings |
Per-chunk embeddings with text and offset |
tldr |
AI-generated summary of the page |
tags |
Extracted topic tags |
entities |
Named entities found in the content |
readingTime |
Estimated reading time |
wordCount |
Word count of the content |
credibility |
Source credibility score |
quality |
Content quality score |
API Key
Get your API key at keirolabs.cloud. The Explorer plan includes 500 free credits.
Development
# Install for development
pip install -e ".[test]"
# Run unit tests
pytest tests/unit_tests/
# Run integration tests (requires KEIRO_API_KEY)
KEIRO_API_KEY=keiro_... pytest tests/integration_tests/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_keiro-0.1.0.tar.gz.
File metadata
- Download URL: langchain_keiro-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d564cb37982ba09f484f2089cca781fe5bf685ab71c15ace8cd6eace9da4241
|
|
| MD5 |
f0ebe8b1a32eb25184911433722e22bb
|
|
| BLAKE2b-256 |
bf9f68ddd7faca831de42b93bab079e0919282295fad23c32449065229125a06
|
File details
Details for the file langchain_keiro-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_keiro-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a54404f0992dad4ea14c47e98ec1125cc511647bfc8a76f312234b9d61431bb
|
|
| MD5 |
fbfdb1abfc9e0db8838e1365536e1042
|
|
| BLAKE2b-256 |
cafdc56057fe7eb1a5ec03dfb6d9c5db8fcb777147c61c10b1133dcb17e34d72
|