LangChain retriever for knowledgelib.io — pre-verified, cited knowledge units for AI agents
Project description
langchain-knowledgelib
LangChain retriever for knowledgelib.io — pre-verified, cited knowledge units for AI agents.
Installation
pip install langchain-knowledgelib
Quick Start
from langchain_knowledgelib import KnowledgelibRetriever
retriever = KnowledgelibRetriever(k=3)
docs = retriever.invoke("best wireless earbuds under 150")
for doc in docs:
print(f"[{doc.metadata['confidence']}] {doc.metadata['canonical_question']}")
print(doc.page_content[:200])
print()
Configuration
| Parameter | Default | Description |
|---|---|---|
api_url |
https://knowledgelib.io |
Base URL (change for self-hosted instances) |
k |
3 |
Number of results (1-20) |
domain |
None |
Filter by domain (e.g., "consumer_electronics", "computing", "home") |
fetch_full_content |
True |
Fetch full markdown or just canonical question text |
api_key |
None |
Optional API key (not required for the free public API) |
Document Metadata
Each returned Document includes rich metadata from knowledgelib.io:
doc.metadata = {
"source": "knowledgelib.io",
"id": "consumer-electronics/audio/wireless-earbuds-under-150/2026",
"canonical_question": "What are the best wireless earbuds under $150 in 2026?",
"confidence": 0.88, # 0.0-1.0, based on source quality
"last_verified": "2026-02-07",
"source_count": 8, # number of cited sources
"freshness": "high", # high/medium/low
"token_estimate": 1800, # approximate token count
"relevance_score": 0.97, # search relevance
"url": "https://...", # human-readable page
"raw_md": "https://...", # raw markdown URL
}
Use in a RAG Chain
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
retriever = KnowledgelibRetriever(k=2, domain="consumer_electronics")
prompt = ChatPromptTemplate.from_template(
"Answer based on these verified knowledge units:\n\n{context}\n\nQuestion: {question}"
)
chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt
| ChatOpenAI()
)
result = chain.invoke("best noise cancelling headphones under 200")
Async Support
docs = await retriever.ainvoke("best wireless earbuds under 150")
What is knowledgelib.io?
An AI Knowledge Library with structured, cited knowledge units optimized for AI agent consumption. Each unit answers one canonical question with full source provenance, confidence scoring, and freshness tracking. Pre-verified answers that save tokens ($0.02/query vs $0.50-$5.00 in agent compute), reduce hallucinations, and cite every source.
- 172+ knowledge units across 11 domains
- Free API, no authentication required
- API Documentation
- OpenAPI Spec
License
CC BY-SA 4.0
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_knowledgelib-0.1.1.tar.gz.
File metadata
- Download URL: langchain_knowledgelib-0.1.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f438cb3784ec025f2d9704bd9804f53200c37c2b7c5c6629807c74825f4a3f4c
|
|
| MD5 |
5f627442e476d33f3fca7f3a2fd9c433
|
|
| BLAKE2b-256 |
b30bea88ae6d6fd844cb1da4866dbaace8cfe166ae9dd0fb39b4367ef17c6930
|
File details
Details for the file langchain_knowledgelib-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langchain_knowledgelib-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8beb082cf871257e345734c80b08ea1894dbcc982cb3be2efa1b197304382506
|
|
| MD5 |
5ea4650979f88844a494cdb93d12f497
|
|
| BLAKE2b-256 |
e06fbf59f4f0ad1f6f2b311a9eb3ba8fc1ba72ad4b2f9eff2ea06adab1ed5d30
|