1

I try to comprehend how the vectorstore.asRetriever() method operates.

This exercise aims to guide semantic searches using a metadata filter that focuses on specific documents. There may be instances where I need to fetch a document based on a metadata labeled code, which is unique and functions similarly to an ID. In such cases, a semantic search would need to be performed on just this specific document out of the 100k documents stored in the Pinecone database.

How can I go about implementing this? Is there an alternative approach? I've tried to look for solutions in the LangChain JS documentation but have yet to find one.

My code:

export const makeChain = (vectorstore: PineconeStore) => {
  const model = new OpenAI({
    temperature: 0,
    modelName: 'gpt-3.5',
  });

  const metadataFilter = { location: 'Paris' };

  const chain = ConversationalRetrievalQAChain.fromLLM(
    model,
    vectorstore.asRetriever(10, metadataFilter),
    {
      qaTemplate: QA_PROMPT,
      questionGeneratorTemplate: CONDENSE_PROMPT,
      returnSourceDocuments: true,
    },
  );
  return chain;
};

Documentation

asRetriever()

asRetriever(k?: number, filter?: object): VectorStoreRetriever<VectorStore>

Parameters:
Parameter   Type
k?          number
filter?     object
Returns

VectorStoreRetriever<VectorStore>
  asRetriever(
    k?: number,
    filter?: this["FilterType"]
  ): VectorStoreRetriever<this> {
    return new VectorStoreRetriever({ vectorStore: this, k, filter });
  }
}

vetheve
  • 209
  • 1
  • 2
  • 9

0 Answers0