Skip to main content

SQL-style semantic query language and retrieval middleware for Agents & RAG

Project description

NLQL

PyPI version Python License: MIT Documentation

English · 简体中文 · 在线文档

NLQL lets you do semantic search with SQL-style statements. Relevance scoring, filtering, and sorting live in one query — no more scattered embedding calls and post-processing code.

Built for Agent and RAG applications: the query itself is structured data, usable directly as an LLM tool-call payload.

What it looks like

import nlql

engine = nlql.Engine(nlql.embed.FakeEmbedder())  # or OpenAIEmbedder, or any Embedder
engine.add_text("AI agents plan tasks and call tools.", metadata={"status": "published"})
engine.add_text("Banana bread needs flour and sugar.", metadata={"status": "draft"})

for unit in engine.search('''
    SELECT SENTENCE
    LET rel = SIMILARITY(content, "autonomous agents")
    WHERE rel >= 0.2 AND meta.status == "published"
    ORDER BY rel DESC
    LIMIT 5
'''):
    print(f"{unit.scores['rel']:+.3f}  {unit.content}")

The statement reads almost like SQL: SELECT sets the return granularity, LET computes relevance, WHERE filters, ORDER BY / LIMIT sort and cap.

Features

  • One statement, full intent — relevance, filtering, and sorting in one place, not scattered across business code
  • Three ways to write, identical results — SQL statement, Python chained builder, or JSON IR; all compile to the same internal representation
  • Pluggable backends — built-in store works out of the box; switch to Qdrant / Faiss / Chroma / HnswLib / pgvector with one line
  • Two-stage retrieval — attach a reranker after recall for higher accuracy
  • Multimodal — text and images share one vector space; retrieve images with text
  • Explainableengine.explain() prints the query plan

Installation

pip install python-nlql

Optional extras:

Command Purpose
pip install "python-nlql[faiss]" Faiss backend
pip install "python-nlql[hnsw]" HnswLib backend (for large-scale data)
pip install "python-nlql[qdrant]" Qdrant backend
pip install "python-nlql[chroma]" Chroma backend
pip install "python-nlql[pgvector]" Postgres + pgvector backend
pip install "python-nlql[local]" local sentence-transformers / CLIP / cross-encoder
pip install "python-nlql[loaders]" DOCX / PDF file loaders

Switching backends

One line; ingestion and query code stay the same:

from nlql.store.qdrant_store import QdrantStore
engine = nlql.Engine(embedder, store=QdrantStore(location=":memory:"))

Documentation

Full docs, tutorials, and API reference: https://natural-language-query-language.github.io/python-nlql/en/

More examples in the examples/ directory.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_nlql-0.3.2.tar.gz (217.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_nlql-0.3.2-py3-none-any.whl (108.4 kB view details)

Uploaded Python 3

File details

Details for the file python_nlql-0.3.2.tar.gz.

File metadata

  • Download URL: python_nlql-0.3.2.tar.gz
  • Upload date:
  • Size: 217.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_nlql-0.3.2.tar.gz
Algorithm Hash digest
SHA256 adcda948c0c4dd80678c33f5b147e01551df25fe1ec3779715fd0a9a2b5b56d1
MD5 43928d9685a530062b91f641bf1ff21d
BLAKE2b-256 ebee6f38510bed0789d586b7c69723358a776d76aa4631eb05ef9d06b194a253

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.2.tar.gz:

Publisher: publish.yml on natural-language-query-language/python-nlql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_nlql-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: python_nlql-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 108.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_nlql-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72f5e48f4112aa1e59bfb1e0a2e220bab6602131562d336779cca19479f86fd7
MD5 987c7cb2c8c8e4d6de1e05ace152140e
BLAKE2b-256 5f9d05e844140d083608850b61ac603f8dbac6062205194606d9c72ec69bd04b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.2-py3-none-any.whl:

Publisher: publish.yml on natural-language-query-language/python-nlql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page