How do i filter and show response from latest file using my PGVector

457 views Asked by At

In langchain embeddings using PGVector if the user asks question and it matched 2 files. I need to show the response with the latest uploaded file. In my embeddings when a file is uploaded i am storing it as timestamp_file_name. Please let me know on how to retrieve the latest file in python while querying.

def get_vector_store(auth_id,openai_key): """ Creates and returns a vector store for storing product embeddings.

Returns:
PGVector: The vector store instance.
"""
# PGVector
vector_store = PGVector(
    embedding_function=OpenAIEmbeddings(
        openai_api_key=openai_key, max_retries=MAX_RETRIES),
    collection_name=auth_id,
    connection_string=CONNECTION_STRING,
    distance_strategy=DISTANCE_STRATEGY
)
return vector_store

llm = ChatOpenAI( temperature=0, ) chain = RetrievalQAWithSourcesChain.from_chain_type( llm=llm, chain_type="stuff", retriever=self.vector_store.as_retriever(search_type=SEARCH_TYPE, search_kwargs=SEARCH_KWARGS), chain_type_kwargs=chain_type_kwargs, return_source_documents=True, memory = window_memory ) chain_response = chain(user_input)

how do I filter in PGVector

1

There are 1 answers

0
kenny On

You can use the filter method link

# Use a filter to only retrieve documents from a specific paper
db.as_retriever(
    search_kwargs={'filter': { {'source':'id'}}}
)