scikit-learnlangchainragvectorstore

Is there a way to load a saved SKLearn VectorStore using langchain?


I created and saved a vectorstore using langchain_community.vectorstores SKLearnVectorStore and I can't load it.

I created and saved vectorstore as below:

from langchain_community.vectorstores import SKLearnVectorStore

vectorstore = SKLearnVectorStore.from_texts(
    texts=doc_splits,
    embedding=OllamaEmbeddings(model="Gemma-2:9b"),
    persist_path="assets/vectorstore",
)
vectorstore.persist()

I want to use this vectorstore in another file how do I use it?


Solution

  • Save the Vectors

    vectorstore = SKLearnVectorStore.from_documents(
            documents=doc_splits,
            persist_path=PERSIST_PATH,
            embedding=OllamaEmbeddings(model="Gemma-2:9b"),
            serializer="parquet",
        )
    
    vectorstore.persist()
    

    Load the Saved parquet file

    vectorstore = SKLearnVectorStore(
                persist_path=PERSIST_PATH,
                embedding=OllamaEmbeddings(model="Gemma-2:9b"),
                serializer="parquet"
            )
    docs = vectorstore.similarity_search(query)
    

    *Note: PERSIST_PATH is the path where you would like to save the file and load it.

    Refer: https://python.langchain.com/docs/integrations/vectorstores/sklearn/*