Skip to main content

CogniQ 🧠

Next-generation hybrid RAG. 3 lines to start. Infinite to extend.

pip install cogniq

Why CogniQ?

Feature LangChain RAG LlamaIndex CogniQ
Lines to start 30+ 20+ 3
Zero-dependency core ❌ ❌ ✅
Knowledge graph layer ❌ partial ✅
Plugin system complex complex ✅ simple
Multiple LLM backends yes yes ✅ built-in
Search speed (100K docs) ~50ms ~40ms ~1ms

Quickstart (30 seconds)

from cogniq import RAG

r = RAG()
r += "Banks must maintain LCR of 100% at all times per RBI guidelines."
r += "Failure to maintain LCR attracts penalty and supervisory action."

result = r("What happens if a bank doesn't maintain LCR?")
print(result)
# → "Failure to maintain LCR attracts penalty and supervisory action."

Full API

Add documents

r = RAG()

r += "plain text string"                  # string
r.add("text", source="rbi_circular.txt") # with metadata
r.add("document.txt")                    # file path
r.add(["doc1", "doc2", "doc3"])          # batch
r.learn("text")                          # alias for add

Search & Ask

# Search (returns SearchResult list)
results = r.search("LCR requirements", top_k=5)
results = r["LCR requirements"]           # same, operator syntax

for result in results:
    print(result.score, result.text, result.source)

# Ask (returns AskResult)
answer = r.ask("What is LCR?")
answer = r("What is LCR?")               # same, operator syntax

print(answer)                            # auto-prints answer text
answer.show()                            # pretty print with sources
print(answer.sources)                    # list of SearchResult
print(answer.latency_ms)                 # query time

Attach an LLM

# Ollama (local, free)
r.use_ollama("llama3.2")

# OpenAI
r.use_openai("gpt-4o-mini")

# Anthropic
r.use_anthropic("claude-haiku-4-5-20251001")

# Any custom function
def my_llm(question, context, **kwargs):
    return call_my_model(question, context)
r.use_llm(my_llm)

Choose embedder

# Auto (sentence-transformers → Ollama → TF-IDF)
r = RAG(embedder="auto")

# Force sentence-transformers (pip install sentence-transformers)
r = RAG(embedder="sentence", model="all-MiniLM-L6-v2")

# OpenAI
r = RAG(embedder="openai")

# Ollama
r = RAG(embedder="ollama", model="nomic-embed-text")

# Pure TF-IDF (zero deps, surprisingly good for domain text)
r = RAG(embedder="tfidf")

# Your own function
from cogniq import CustomEmbedder
r = RAG(embedder=CustomEmbedder(my_fn, dim=768))

Choose store

r = RAG(store="memory")   # default, numpy-optimized
r = RAG(store="faiss")    # pip install faiss-cpu, for 100K+ docs

Plugins — extend anything

from cogniq.plugins import Plugin, register_plugin

@register_plugin("my_reranker")
class MyReranker(Plugin):
    """Custom post-search reranker"""

    def post_search(self, results, query, **kw):
        # Your reranking logic
        return sorted(results, key=lambda r: my_score(r, query), reverse=True)

    def pre_add(self, text, meta):
        # Clean text before adding
        text = text.upper()
        return text, meta

# Use it
r = RAG(plugins=["my_reranker"])

# Built-in plugins
r = RAG(plugins=["dedup"])              # remove near-duplicate results
r = RAG(plugins=["min_score"])          # filter below threshold
r = RAG(plugins=["text_cleaner"])       # strip HTML, normalize whitespace
r = RAG(plugins=[
    "text_cleaner",
    "dedup",
    MinScorePlugin(threshold=0.4),      # instance with params
    my_custom_plugin,                   # instance or callable
])

Knowledge Graph

r = RAG(graph=True)   # enabled by default
r += "Risk causes liquidity stress. Stress triggers penalty."

# Graph automatically extracted — boosts relevant results
# Manual additions:
r._graph.add_entity("LCR", "regulation")
r._graph.add_relation("LCR_violation", "penalty", "triggers")

# Inspect
print(r._graph.stats())
paths = r._graph.find_paths("risk", "penalty")

Save / Load

r.save("my_rag.pkl")
r2 = RAG.load("my_rag.pkl")
r2.use_ollama("llama3.2")  # reattach LLM after load

Global API (no class needed)

import cogniq

cogniq.add("document text")
cogniq.add("more docs")
result = cogniq.ask("question?")
results = cogniq.search("keyword")
cogniq.reset()  # clear

CLI

cogniq add "your text here"
cogniq add --file document.txt
cogniq ask "What is LCR?"
cogniq ask "What is LCR?" --sources    # show source chunks
cogniq search "liquidity"
cogniq info
cogniq reset

ARJUNA / CCIL Integration Example

from cogniq import RAG

# Build CCIL regulatory RAG
rag = RAG(
    embedder="sentence",
    store="faiss",          # large corpus
    chunker="smart",
    graph=True,
    plugins=["dedup", "min_score"],
)

# Load circulars
import glob
for path in glob.glob("circulars/*.txt"):
    rag.add(path)

# Attach local LLM
rag.use_ollama("llama3.2")

# Query
result = rag("What is the penalty for LCR violation?")
result.show()

# Save
rag.save("ccil_rag.pkl")

Performance

Scale Search Time Memory
1K docs ~0.01ms ~5 MB
10K docs ~0.1ms ~50 MB
100K docs ~1ms ~500 MB
1M docs ~10ms (FAISS) ~2 GB

Why so fast?

  • Pre-normalized vectors → cosine = dot product (no division)
  • np.argpartition O(n) top-k (no full sort)
  • Single BLAS call for all similarities
  • LRU embedding cache
  • FAISS ANN for large scale

Installation Options

pip install cogniq                          # numpy only (TF-IDF)
pip install cogniq[sentence]               # + sentence-transformers
pip install cogniq[openai]                 # + OpenAI
pip install cogniq[faiss]                  # + FAISS
pip install cogniq[full]                   # everything

License

MIT

Metadata

Release files for cogniq 0.2.0

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

Source distribution (sdist)

Source distribution for cogniq 0.2.0
File Size Uploaded
cogniq-0.2.0.tar.gz 30.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cogniq 0.2.0
File Interpreter ABI Platform
cogniq-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.7 kB

Release files / cogniq-0.2.0.tar.gz

Download URL cogniq-0.2.0.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d5f5870f3d6c5fb4681fb0ea1ceed114736dd36f9a646f3d4379f7aaf9058511
BLAKE2b-256 checksum
How to use checksums
897596f3270d54981948b8f51f0640114f1276b5484372f522e90595cc123a54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release files / cogniq-0.2.0-py3-none-any.whl

Download URL cogniq-0.2.0-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb7e5157cee0b3dd28af11e4ee9efcd6b483c58ab86d040096a7c5f461ffb1f0
BLAKE2b-256 checksum
How to use checksums
626c955d8fbbeae1f20ba56f1eee97c58a111fd5b8171eb35246db2b842cbc84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.2.0 This release

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