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
You can use the filter method link