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.11.dev0-cp314-cp314-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.14Windows x86-64

fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11.dev0-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

fabricatio_rag-0.1.11.dev0-cp313-cp313-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11.dev0-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_rag-0.1.11.dev0-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_rag-0.1.11.dev0-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ffe29f9ed51b0d2234df24cb2ed005010335d0ccdba909ba16adb6a32b69dee1
MD5 dd3ff8c96464d2898ce6dc549e25f2eb
BLAKE2b-256 5321f3076a02e423e9c2ccb3a8640e58eba6e48409e3d9a0ddd97571c8781dda

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9bc8dd02b31ca84eda6984564b256e6f4d1949de4771e8154587bdbf212986d2
MD5 ff6b54e1ee916facd42734c82f0b3e44
BLAKE2b-256 c0b15b004bdb6cd5fe72cd934084ab7400cb5ae8d06d4ed00e69bc61e1d58446

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 22c42ffe3cb850b49413758285d107b6bbf7ce9225c257359f6b589f1644cf25
MD5 933c9306885f0c03fe7bf5bcff5dd61c
BLAKE2b-256 9357a985d1253bd97122a6ca1fcfcdd293dee5f347091c366ee0b27ab23301cb

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fd1161b76865c0d83cb3afc52762bdd3d3336a1819f1038756cc9d411354fcf
MD5 166c4c77961bdecfdc304177b5d16830
BLAKE2b-256 19912aaebbf24e4e9ed138b87c974c2ee04a3c5998e5f75980d533b460c95e05

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 84c9c17fe5fbc1397b6735cdf3500d913d7d157aac7bf1bcbd621f1f18254a09
MD5 0e562ebd82cfee82a4a0b8bdb1a2dbcd
BLAKE2b-256 2c01e20ca1e802f26beef3dad0d2fdfa5210e87b05aa29ab70b14d35db4466b0

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c2ea0c505b5d9d384d306840678cd12e8ad3e8a46c6f00c68c71b0107f1d483e
MD5 bf2f13c1c0286e2c39f67097196ae1d2
BLAKE2b-256 6568150249553cc81a6c00630592db76e8904eed850823488733dac698392c84

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b95e554ad792e393aa671a093a6483a6fab3c1be0d09adb8aa692988c03b40e6
MD5 e1c424736b16090dda9a81291b48b2f8
BLAKE2b-256 cc27d96b41cc879373405de4264cd44d2a2fe721cfc4c64c76ba7be9888da6f9

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3abd9629f5a0173bdb8741cde30a49a4a881742dde4f5c8fc27f59b2ec8ed0a1
MD5 3d65846975803f35cb48c2fed60e6deb
BLAKE2b-256 ec004f83eab1c015ded5294684d1b47100d88ca62ca61921ae6b615009a9c0fb

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a3803cd1e4f5b3d994d456353b109fc7f8391676c114d2b6fc38631037c400ee
MD5 f26540f23e5e26509a51b79d57937595
BLAKE2b-256 1709a6fb29fced5235d7a132b66b21431e97ce5c963e097fec4d0389dde33987

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 487012541f0ad570d68e88cbdbf440dcdc0a2d0ba65fc581ad9a3b1011d40ed2
MD5 6fc7732c117ab6fe595bf79b02c7a4e4
BLAKE2b-256 c7ec22fc14073c0d652bed4415e160fc4f9dd605d864fe4e56dc311bafbd4717

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ae52654b0684d19b5b76a3ecc5ee13bfd8817b42ce9a2032b9cab9827e4e6a44
MD5 13ba54e2bf8cb6626eff288b27412d98
BLAKE2b-256 f0026f6c62282a5763c82e244f2fb85e1e9a75c329e4805add138bb411a91982

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.11.dev0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fabricatio_rag-0.1.11.dev0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4986349f86478dc93f0907d9ab50356f88cc8e3a543d278790dae01c6df02edf
MD5 ce647e5611466c897c1c1324e1f7e57d
BLAKE2b-256 a3db8a3aa8e81c827a9c9e8eb5ce50fd6790e51eb659b52403a93fe0a2bb841a

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