Skip to content

RAG Integration#426

Draft
RLKRo wants to merge 9 commits intodeeppavlov:devfrom
RLKRo:feat/rag-integration
Draft

RAG Integration#426
RLKRo wants to merge 9 commits intodeeppavlov:devfrom
RLKRo:feat/rag-integration

Conversation

@RLKRo
Copy link
Member

@RLKRo RLKRo commented Mar 31, 2025

Description

Add RAG integration.

Checklist

  • I have performed a self-review of the changes

To Consider

  • Add tests (if functionality is changed)
  • Update API reference / tutorials / guides
  • Update CONTRIBUTING.md (if devel workflow is changed)
  • Update .ignore files, scripts (such as lint), distribution manifest (if files are added/deleted)
  • Search for references to changed entities in the codebase

SPI315 and others added 2 commits March 30, 2025 23:16
• Added VectorStoreService base class with config model
• Implemented ChromaVectorStore integration with HuggingFace embeddings
• Created RetrieverService for document search in pipeline
• Updated docker-compose for Chroma
• Excluded from pipeline flow (WIP)

TODO: Connect to pipeline services (in progress)
@RLKRo RLKRo added the enhancement New feature or request label Mar 31, 2025
self.vector_store = QdrantClient(url=vector_store_url)
self.retriever = SentenceTransformer(retriever_model)

def execute(self, user_query: str, ctx: Dict[str, Any], **kwargs) -> Dict[str, Any]:
Copy link
Member Author

@RLKRo RLKRo Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See response_tutorial for information on how to subclass BaseResponse.

context = "\n".join([hit.payload["text"] for hit in results])
ctx["cached_rag_context"] = context

prompt = f"Контекст: {context}\nВопрос: {user_query}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like prompt customization (i.e. ability to change prompt template via __init__).

def __init__(self, vector_store_url: str, retriever_model: str, **kwargs):
super().__init__(**kwargs)
self.vector_store = QdrantClient(url=vector_store_url)
self.retriever = SentenceTransformer(retriever_model)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot use local models:

  • additional heavy dependencies;
  • CPU load.

Comment on lines +1 to +4
from typing import Dict, Any
from sentence_transformers import SentenceTransformer
from qdrant_client import QdrantClient
from chatsky.responses.base_response import BaseResponse
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an empty line separating import groups (pep-8):

Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.

Imports should be grouped in the following order:

Standard library imports.
Related third party imports.
Local application/library specific imports.

You should put a blank line between each group of imports.

from typing import Dict, Any

from sentence_transformers import SentenceTransformer
from qdrant_client import QdrantClient

from chatsky.responses.base_response import BaseResponse


def execute(self, user_query: str, ctx: Dict[str, Any], **kwargs) -> Dict[str, Any]:
if "cached_rag_context" in ctx:
context = ctx["cached_rag_context"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context and ctx are similar parameter names which can be confusing. It's better to rename context to something else (e.g. rag_context).

assert docs == expected_docs


async def test_retriever_with_threshold(pipeline_with_retrievers):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these two tests were previously implemented as one parametrized test in order to keep them grouped (since both are tests for retriever), you can achieve this with test classes instead:
https://docs.pytest.org/en/stable/getting-started.html#group-multiple-tests-in-a-class

So it would look like

class TestRetriever:
  async def test_get_documents(self, pipeline_with_retrievers):
  async def test_threshold(self, pipeline_with_retrievers):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants