Skip to content

Implement vector store caching for resume_rag_tool #2

@coderabbitai

Description

@coderabbitai

Background

In PR #1 (#1 (comment)), a performance improvement was identified for the resume_rag_tool function.

Issue

Currently, the resume is processed and indexed on every query, which is inefficient for repeated use, especially when the content of the resume doesn't change frequently.

Proposed Solution

Implement a caching mechanism for the vector store:

  1. Add a global _vector_store variable to cache the FAISS index
  2. Check if the vector store exists before creating a new one
  3. Only process and index the resume if the vector store isn't already cached
  4. Add proper logging for when a new vector store is created

Implementation Details

# Global variable to cache the vector store
_vector_store = None

@tool("resume_rag_tool")
def resume_rag_tool(input: str) -> str:
    # Existing code...
    
    try:
        global _vector_store
        
        # Use cached vector store if available
        if _vector_store is not None:
            retriever = _vector_store.as_retriever(search_kwargs={"k": 3})
        else:
            # Process and index the resume if not cached
            # Add proper logging here
            # Load and process documents...
            
            # Create FAISS vector store
            _vector_store = FAISS.from_documents(docs, embeddings)
            retriever = _vector_store.as_retriever(search_kwargs={"k": 3})

Additional Considerations

  1. Consider adding a timestamp or hash check to invalidate the cache if the resume file changes
  2. Ensure proper logging is implemented with the right imports
  3. Implement a way to force a refresh of the vector store if needed

This improvement will significantly enhance performance for repeated queries to the resume tool.

Reference: PR #1 discussion: #1 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions