pythonopenai-apilangchainopenaiembeddings

Not getting source documents from chain in langchain and openAI embeddings


I'm loading pdfs using langchain.document_loaders:

loader = DirectoryLoader( './files/', glob='*.pdf', loader_cls=PyPDFLoader)

then splitted the docs, created the embeddings, stored and loaded them :

docsearch = Chroma.from_documents(texts, embeddings, persist_directory=persist_directory)

...

docsearch = Chroma(persist_directory, embedding_function=embeddings ) 
retriever = docsearch.as_retriever( search_kwargs={"k": 5})
docs = retriever.get_relevant_documents( query )
len( docs)

I'm getting a correct response but I'm getting 0 source documents.


Solution

  • The error is in:

    docsearch = Chroma(persist_directory, embedding_function=embeddings ) 
    

    should be:

    docsearch = Chroma(persist_directory=persist_directory, embedding_function=embeddings )