Skip to main content

A Python library for Retrieval-Augmented Generation (RAG) capabilities in LLM applications.

Project description

fabricatio-rag

A Python library for Retrieval-Augmented Generation (RAG) capabilities in LLM applications.

📦 Installation

This package is part of the fabricatio monorepo and can be installed as an optional dependency:

pip install fabricatio[rag]

Or install all components:

pip install fabricatio[full]

🔍 Overview

Provides tools for:

  • Document embedding and vector storage using Milvus This feature uses the Milvus vector database to store document embeddings. Document embeddings are numerical representations of text documents that capture their semantic meaning. The library first converts text documents into embeddings using appropriate embedding models. These embeddings are then stored in Milvus, which provides efficient storage and retrieval capabilities. For example, it can handle large - scale document collections and perform fast similarity searches.
  • Semantic search and context retrieval The semantic search and context retrieval feature allows users to search for relevant documents based on the meaning of their queries. It uses the stored document embeddings in Milvus to find documents that are semantically similar to the query. This is more powerful than traditional keyword - based search as it can understand the intent behind the query. For example, if a user searches for "effects of pollution on wildlife", it can retrieve documents that discuss related concepts even if the exact keywords are not present.
  • Integration with TEI (Text Embeddings Inference) services The integration with TEI services enables the generation of text embeddings. TEI services provide pre - trained models that can convert text into embeddings. The library can send text data to the TEI service and receive the corresponding embeddings. This allows for the use of state - of - the - art embedding models without having to manage the model training and inference process locally.
  • Database injection workflows The database injection workflows are responsible for inserting new documents into the Milvus database. It takes care of the process of converting the documents into embeddings, and then inserting them into the appropriate collections in Milvus. This includes handling tasks such as collection creation, data indexing, and error handling.
  • Asynchronous RAG execution patterns The asynchronous RAG execution patterns allow the library to perform multiple RAG tasks concurrently without blocking the main thread. This is useful for improving the performance and responsiveness of the application. For example, it can handle multiple user queries simultaneously, reducing the overall response time.

Built on top of Fabricatio's agent framework with support for asynchronous execution and Rust extensions.

🧩 Usage Example

from fabricatio_rag.capabilities.rag import RAG
The `RAG` class is the core component of the library. It provides methods for performing retrieval - augmented generation tasks. It interacts with the Milvus database for document retrieval and uses the generated embeddings to augment the generation process.
from fabricatio_rag.models.rag import MilvusDataBase
The `MilvusDataBase` class represents the connection to the Milvus vector database. It provides methods for creating collections, inserting documents, and performing searches. It abstracts the low - level details of working with Milvus, making it easier to use in the application.


async def search_knowledge():
    # Initialize database connection
    db = MilvusDataBase(collection_name="science_papers")
    This line initializes a connection to the Milvus database with a specific collection named "science_papers". The collection is where the document embeddings will be stored and retrieved from.

    # Initialize RAG capability
    rag = RAG(db)
    This line creates an instance of the `RAG` class, passing in the `MilvusDataBase` object. This allows the `RAG` class to interact with the Milvus database for document retrieval.

    # Search for relevant information
    results = await rag.retrieve("climate change impact on coral reefs", limit=3)
    The `retrieve` method of the `RAG` class is used to perform a semantic search in the Milvus database. It takes a query string and a limit as parameters. In this example, it searches for documents related to "climate change impact on coral reefs" and returns the top 3 relevant documents.

    print("Top 3 relevant documents:")
    for result in results:
        print(f"- {result['title']}")
        print(f"  Relevance: {result['score']:.2f}")
        print(f"  Snippet: {result['text'][:150]}...")

📁 Structure

fabricatio-rag/
├── actions/          - Data injection workflows
├── capabilities/     - Core RAG functionality
├── models/           - Database and query models
├── proto/            - TEI service definitions
└── rust.pyi          - Rust extension interfaces

🔗 Dependencies

Core dependencies:

  • pymilvus>=2.5.4 - Vector database integration
  • fabricatio-core - Core interfaces and utilities

Rust extensions:

  • TEI client bindings
  • Protobuf definitions for gRPC communication

📄 License

MIT – see LICENSE

GitHub: github.com/Whth/fabricatio

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

fabricatio_rag-0.1.9-cp313-cp313-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.9-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_rag-0.1.9-cp312-cp312-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.9-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fabricatio_rag-0.1.9-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f4ec396be975e764d4c73e7aed567cd71927bd698ccc8722749811b5b9417808
MD5 84af2634d726c43f214861507d3b45a9
BLAKE2b-256 359165b6ab567ec0994bc1e16e8b2a00c477eda2114b67f2cacb41283936c04f

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a4f4ef11f624a8bfd869581f6f57e5ea8e3f3b150189c5260ec2c09f1065df0e
MD5 80dc74a05d98b59146186224050e7ca4
BLAKE2b-256 0970190d7f42e16f1492b9f88b74b890ea0926c51b056ea7aae9053b4b908f30

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 648ae7a4ba6db27f040161af5b8cc907c6f8147ccb7a4c43349b203ec888d798
MD5 3a5e209d8c1720bc67003ea2d3fce05c
BLAKE2b-256 63ec5faa92a9077646760c94cc328f627944a1acab5cb3eaf5b9cd306c7dbe7c

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f84d11969925fd2da2dec43274d7fed508843025c642051413eb9655d799ac6a
MD5 5c92f1f65be79b6bb11031aab6113c28
BLAKE2b-256 55e1f8840f243797e6ef661ebd0dae66af26fda81266e3a3ee1920bbdd75e6bd

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aa71e5a6dcc9299f50fbc0040ffe9888646669711946bbbff38bc207a7ca909b
MD5 4ec96dfdff6e6fbf2ff3b2ab4373d61b
BLAKE2b-256 4ca15f0c65cc9205c5c4d23789bb0bf7a318960f6576371e85ab3be9f83434a7

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1430d25c9b01ba03b3fe196e4a5f4a1f1e9e39d0f84370bd687c8a6ad3d4246f
MD5 a8bb2f6554bf875ca3fccf62b5bf68a4
BLAKE2b-256 94ad5245dd4c5af433ed56baf4c3678762f654ac81514edcd83da9001ac5fde7

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f2b534604d056c4676f4283d10bf2c0c869ed1dbd35cf04894d48ff96a4d273f
MD5 c92984da865b24aba9bb2d88b33509d3
BLAKE2b-256 abc3d267eb71f7311c960e615e589e8d0272deaed05064491ea34107c521616c

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fdeb5201f32ff4124e322648a194ebe9380bcadd273e35af9815804e9f1f9448
MD5 46994db7da4020edb6f68d949cc51534
BLAKE2b-256 efbd062db51330ff98cbd40158f3fff46f3cef7f842e3061bce27eaf66e1b2d9

See more details on using hashes here.

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