Skip to main content

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

Project description

fabricatio-rag

MIT Python Versions PyPI Version PyPI Downloads PyPI Downloads Bindings: PyO3 Build Tool: uv + maturin

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 using either pip or uv:

pip install fabricatio[rag]
# or
uv pip install fabricatio[rag]

For a full installation that includes this package and all other components of fabricatio:

pip install fabricatio[full]
# or
uv 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

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.13.dev1-cp314-cp314-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.14Windows x86-64

fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.13Windows x86-64

fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.12Windows x86-64

fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 482a3be3b9a0b6fda38a78f69314c8f8f7a1b7a44ba253c51e88c1f2a855de2a
MD5 7898fbb961f7017adfee59bdb5db4afd
BLAKE2b-256 d994c82933b8454fc26b9288787d68d3972622b847c5d16e057e16e169fd5e89

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 74b46d50d5e885783af47378b7fd0c7756d836c2855c5cf8e991a0eed0dbbfc7
MD5 469678639ccd98d2f080b5a742333d1f
BLAKE2b-256 eed104b7a79b0ac570a8100334115cef5c5e185c57c01523604aba3cdb06753d

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2b9c2a3565959ae2dbaa0cb8fe53b0a8e1f60c0db3d2a00326afb292c2b1ed60
MD5 820addbac137fed8f0b8e0327e5918f7
BLAKE2b-256 b010c92456b6e1f9f045a1e84b4291472b2314278f834e4e45398d3a4cd0bd8e

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7a62afc6642eafc263a515f464b81a7e3116ae7b638f0dfcba974ea1b059ebe3
MD5 492cc6d45e4a0b0fdb607a16f39e8a7c
BLAKE2b-256 5c2cd04899d6258e5c9d3a12bef5c63ea980edce49076b96902f869683107507

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 190ec4f0c24c5755c5116bea300344076751ee3d32cdbf5112d7f6050b0ece80
MD5 b3ef1e5d9c75afdf0069fed59c38c335
BLAKE2b-256 785bce3d974712e430e77f39f5d0e18cf0bdb95335dfee4d245ccdab431a41cf

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 52ae0e20f916da750f4b2f0ee9fec86da832ae60b780a790fff3cada2f517ad5
MD5 4cee64759c6745a64c7e0c6ecfdf3e7e
BLAKE2b-256 14403db32c647c60aad529056a1ca3d179e178ef189ded80f8df9b935ca7378b

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 30e4e088fe2b9ebac588092df5ea7657b0f225e417ce95a6919b42246cb478ec
MD5 d557df19dcf015032e5a63baed8818be
BLAKE2b-256 cc6c2fbe41d0b05230823049ef8bc76e9508824831b3c97edd21f02575f4f837

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6708ae0ff828a7a16019c0b98c1bb1e61e81e1cda2108dabbba64eb3ea061176
MD5 bc0375ff5b40842701d17d6ec7a2ec56
BLAKE2b-256 7a8c5cf53d87baaa75f8af95b0c1eb33c14623e242ab2bb321e823f2e756affb

See more details on using hashes here.

File details

Details for the file fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_rag-0.1.13.dev1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 07c4035815f276da3b2c6198f74d69418e19e9cd5c0b706e01b546350b08796f
MD5 d9e7f123579e356c389cac60cb8f6c16
BLAKE2b-256 a5e565e907e406da5639d4c5e0dda51fb6dd5f1a2df74718a3884ea354dab743

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