How to create pagination with chromadb search query

190 Views Asked by At
from langchain.vectorstores.chroma import Chroma
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings

@app.route('/search',methods=['POST'])

def searchPost():
    query = request.json['query']
    try:
        embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
        vectordb = Chroma(persist_directory=persist_directory, 
                    embedding_function=embedding_function)    

        output = vectordb.similarity_search(query=query)

        metadata_ids = [doc.metadata['id'] for doc in output]

        return metadata_ids
    except Exception as e:
        print('error',e)
        return 'error'


This is the way to query chromadb with langchain, If i add k= any number, the results are increasing

output = vectordb.similarity_search(query=query, k=40)

So how can I do pagination with langchain and chromadb?

0

There are 0 best solutions below