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.8-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.8-cp313-cp313-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.8-cp313-cp313-manylinux_2_34_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.8-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_rag-0.1.8-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.8-cp312-cp312-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.8-cp312-cp312-manylinux_2_34_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.8-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e4e1e36e24fdcdf0c092057e2519ffb92033f9806a498f3f9f1e35a9e7e5167e
MD5 20ed391165f3d0352516eaadfeaa4af0
BLAKE2b-256 1f0b2cd0191e6d1eae907612fb7f99939c7c21f01862f7c910c17e9c40f0ceaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3273663aa95ddf78fc1c89fea7bdd8a2a2c67ecf8e774c8f18cf002d05195cf2
MD5 0220e6377e27a5041faffcddb02665b2
BLAKE2b-256 63000920b044f98ff6ed74613675c4ee64bd89966f126854eb07438fe61c5a39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8560f916f0214922d0d3321056b555f876670f1461b46f11337fb812d2e7768e
MD5 6215960cecd986fe232e83e85884dde1
BLAKE2b-256 560a20bad881f88624d1c757493559c44502ec2467ebd6950cce62a6572bae17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26d209fa810d0b62af65d082edc003595d6b9489e02c006960d50502add05e5c
MD5 9c07af1bff05f8d56587ba95214c947d
BLAKE2b-256 0b728c05d88de74a766e1cc59b9e98e36f1647ea5782b923e1dcf805f8bc2da9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8fa709a6fd91ea3550c4995f508034ab675ec2f12d4da5cdf5d3b2389466a122
MD5 7eb3a07d786f60d968e104d9c5535f35
BLAKE2b-256 9c65241d374e1d8572346db68b46d3e19710f62d2bcf9e88d554f0df8aa1636e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 81a811adaa5536ad362fade20018efee07556a0b7a44765c97c86da7c64d1565
MD5 705a3fb3903f0681938e9c8f84bf5a13
BLAKE2b-256 0522a68ab5ce03da1757403f62e065a9bf9507065651b98e1f8c79bbe0862f0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1fd7b1c30affd4c6856b833eff2be3800fb32f9b80c03fe9ffbeb6093a559a54
MD5 a0ee29f391fa356060f72248fb60fed1
BLAKE2b-256 9beb96ba07d817b5904ed3e74a51b74cf40201f89fd8186c550fc4812e8afd5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fabricatio_rag-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b85067ad3e746944aaea02622536e6442d806d6422718115e8054b5ef198c0d
MD5 08e9bae7421e92e268652f9b630f2974
BLAKE2b-256 b112af76ab5df8b2b2d99f5a9ef1140c6f5618f219efa6a01fd8174e4fe3c0fa

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