Skip to main content

langchain-modular-rag

提供一个 ModularRAG 类,用于连接已有的 Chroma 知识库并执行在线检索。

Python 3.11 及以上。

安装

pip install langchain-modular-rag

使用

from langchain_modular_rag import ModularRAG

rag = ModularRAG({
    "persist_directory": "./chroma_db",
    "collection_name": "study",
    "embedding_model": "text-embedding-v4",
    "top_k": 5,
    "recall_top_k": 20,
    "pre_retrieval": {
        "enabled": False,
        "rewrite_query": False,
        "hyde": False,
        "model": "qwen-plus",
    },
    "hybrid_retrieval": {
        "enabled": True,
        "weights": [0.5, 0.5],
    },
    "post_retrieval": {
        "enabled": True,
        "deduplicate": True,
        "rerank": False,
        "rerank_model": "qwen3-rerank",
        "similarity_filter": False,
        "similarity_threshold": 0.4,
        "compress_context": False,
        "llm_model": "qwen-plus",
        "reorder": False,
    },
})

results = rag.search("公司打卡时间?")
for document in results:
    print(document.metadata)
    print(document.page_content)

环境变量

需要配置通义 API Key:

export DASHSCOPE_API_KEY="sk-ws-H.YIMERXR.9SE8.MEUCIBPoQYbmuMPUa75FZaI8KMpuEgBGdcZddUD1-H26rhLnAiEApHsvQ_NuiYvD-O7sPBQfxsXLQ1-NAba0MXItASbsKN0"
或
setx DASHSCOPE_API_KEY="sk-ws-H.YIMERXR.9SE8.MEUCIBPoQYbmuMPUa75FZaI8KMpuEgBGdcZddUD1-H26rhLnAiEApHsvQ_NuiYvD-O7sPBQfxsXLQ1-NAba0MXItASbsKN0"

persist_directory 指向已经完成入库的 Chroma 数据库。这个包当前只提供在线检索,不包含你的个人知识库数据,也不会自动创建或导入知识库。

Metadata

Release files for modular-zzz-rag 0.1.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 modular-zzz-rag 0.1.0
File Size Uploaded Provenance Actions
modular_zzz_rag-0.1.0.tar.gz 2.2 kB Without provenance Details for modular_zzz_rag-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modular-zzz-rag 0.1.0
File Interpreter ABI Platform Actions
modular_zzz_rag-0.1.0-py3-none-any.whl Python 3 none any Details for modular_zzz_rag-0.1.0-py3-none-any.whl

Total release size: 4.3 kB

Release files / modular_zzz_rag-0.1.0.tar.gz

Download URL modular_zzz_rag-0.1.0.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1364ab3c242355784a9f3971480468b6cbe7d6e570b92cb154194546159fee7b
BLAKE2b-256 checksum
How to use checksums
de5836142bb2567293de01d7bda10c4536a08c5e6fa0351bba1026ec8dabadda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / modular_zzz_rag-0.1.0-py3-none-any.whl

Download URL modular_zzz_rag-0.1.0-py3-none-any.whl
Size 2.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dd9fb5b7767e6879f79a3f97e6695720e4da061a20f78ec9a628294a114792b
BLAKE2b-256 checksum
How to use checksums
ca4ffb75e1153ec01eb6dd2e56442f1e9175c826a1f8a1c6cba5afebee1bc189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for modular-zzz-rag 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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