Find answers from the community

Updated 9 months ago

How to reuse already created indexes

At a glance

The community member is asking how to properly reuse already created indexes in their index_profiles_data function. When they pass in nodes, the function works well and they can retrieve things. However, when they don't pass in nodes and use from_vector_store, they are unable to retrieve anything.

In the comments, another community member suggests that from_vector_store() is the correct method to use if the vector store is pointing to an existing collection, and it works for them on Pinecone. The original community member acknowledges this and says they will check what they are doing wrong, as they are approaching it correctly.

There is no explicitly marked answer, but the comments suggest that using from_vector_store() is the correct way to reuse an existing index when not passing in nodes.

How to reuse already created indexes properly?

I have a function

Plain Text
def index_profiles_data(
    pinecone_index,
    nodes: Optional[List[BaseNode]] = None,
    namespace: str = "test_namespace",

) -> VectorStoreIndex:
    """Indexes the profiles data using a VectorStore.
    Args:
        nodes: List[BaseNode]: List of nodes to index.
        pinecone_index: Pinecone: Pinecone index object.
        namespace: str: Namespace for the Pinecone vector store.
    Returns:
        VectorStoreIndex: Index that can be used for retrieval and querying.
    """
    # Setup Pinecone Vector Store
    vector_store = PineconeVectorStore(
        pinecone_index=pinecone_index, namespace=namespace
    )
    if nodes:
        storage_context = StorageContext.from_defaults(
            vector_store=vector_store
        )
        # Create Vector Store Index
        vector_store_index = VectorStoreIndex(nodes=nodes, storage_context=storage_context)

    else:
        vector_store_index = VectorStoreIndex.from_vector_store(
            vector_store=vector_store
        )
    logging.info("Vector store index created and ready for use.")
    return vector_store_index


When I pass in the nodes, it works well and I am able to retrieve things. When i dont pass in nodes and use from vector_store it to return anything. How can I resolve this?
L
N
2 comments
from_vector_store() is the correct method to use if your vector store is pointing to an existing collection.

It works for me on pinecone πŸ€”
Thanks. Will check what I am doing wrong. Good to know that I am approaching it correctly.
Add a reply
Sign up and join the conversation on Discord