Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build grounded rag app with vertex with VertexAIRank example confusion #73

Open
QiqiNerd opened this issue Jul 24, 2024 · 2 comments
Open

Comments

@QiqiNerd
Copy link

In the part Step 4. Query in Real Time and Check Grounding of genai-on-vertex-ai/retrieval_augmented_generation/diy_rag_with_vertexai_apis/build_grounded_rag_app_with_vertex.ipynb

The notebook mentioned that this step will "pass retrieved documents to the reranker API via the VertexAIRank" But I only saw the usage of VertexAI class and a basic retriever with the following code:

retriever = vector_store.as_retriever(search_kwargs={"k": 5})

llm = VertexAI(model_name="gemini-1.5-pro-001", max_output_tokens=1024)
template = """
Answer the question based only on the following context:
{context}

Question:
{query}
"""

I feel a bit confused. If I am wrong or I miss something, please correct me! Thank you for your attention to this matter : )

@RajeshThallam
Copy link
Collaborator

@kikiWhite Thanks for the feedback. Please check the step 3.1 in the notebook where reranker is added as part of contextual compression retriever.

from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
from langchain_google_community import VertexAIRank

# Instantiate the VertexAIReranker with the SDK manager
reranker = VertexAIRank(
    project_id=PROJECT_ID,
    location_id="global",
    ranking_config="default_ranking_config",
    title_field="source",  # metadata field to preserve with reranked results
    top_n=5,
)

basic_retriever = vector_store.as_retriever(
    search_kwargs={"k": 5}
)  # fetch top 5 documents

# Create the ContextualCompressionRetriever with the VertexAIRanker as a Reranker
retriever_with_reranker = ContextualCompressionRetriever(
    base_compressor=reranker, base_retriever=basic_retriever
)

Does that help?

@QiqiNerd
Copy link
Author

@RajeshThallam Thank you, Rajesh. Everything is clear now. I understand the use of the contextual compression retriever in step 3.1. I just wanted to kindly point out that step 4 mentioned the use of VertexAIRank, but it wasn't actually used in that step. Just wanted to bring it to your attention. Thanks again for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants