NLQL#
NLQL is a semantic retrieval tool: use SQL-like statements to find relevant content from text.
The canonical form of a query is a serializable intermediate representation (IR). Three forms — NLQL strings, Python chained construction, and LLM tool calls — all compile to the same IR, so their results are identical.
Example#
SELECT SENTENCE
LET relevance = SIMILARITY(content, "AI Agent architecture"),
novelty = SIMILARITY(content, "novel unpublished ideas")
WHERE relevance >= 0.8
AND meta.status != "draft"
ORDER BY relevance DESC, novelty DESC
LIMIT 5
The statement structure mirrors SQL: SELECT specifies the return granularity, LET computes relevance, WHERE filters, and ORDER BY and LIMIT sort and cap results. Relevance scoring, filtering, and sorting are concentrated in a single statement instead of being scattered across business code.
Three forms#
The same query written three ways, with identical results:
Installation#
pip install python-nlql # core
pip install "python-nlql[faiss]" # optional: Faiss backend (also hnsw / qdrant / chroma / pgvector)
pip install "python-nlql[loaders]" # optional: load DOCX / PDF
Features#
- Declarative queries: relevance, filtering, and sorting in a single statement
- Pluggable backends: built-in storage works out of the box; switching to Qdrant, Faiss, or others is a one-line change
- Multimodal: text and images share the same vector space; text can retrieve images
- Explainable:
engine.explain()outputs the query execution plan