Find answers from the community

Updated 3 months ago

Hi guys. Someone could help me in this

Hi guys. Someone could help me in this issue?
I have this code that return the registers from my vector database

Plain Text
def load_saved_index():
    connection_string = "postgresql://testuser:testpwd@localhost:5442/vectordb"
    db_name = "vectordb"
    url = make_url(connection_string)

    vector_store = PGVectorStore.from_params(
        database=db_name,
        host=url.host,
        password=url.password,
        port=url.port,
        user=url.username,
        table_name="dossie",
        embed_dim=1536,
        hnsw_kwargs={
            "hnsw_m": 16,
            "hnsw_ef_construction": 64,
            "hnsw_ef_search": 40,
            "hnsw_dist_method": "vector_cosine_ops",
        },
    )

    storage_context = StorageContext.from_defaults(vector_store=vector_store)
    index = VectorStoreIndex.from_vector_store(
        vector_store=vector_store,
        storage_context=storage_context,
        similarity_top_k=None
    )
    
    return index


the problem is: I have 30 rows and it is returning only two. Someone knows why?
L
J
2 comments
The default top-k is two

You'll need to override it
Plain Text
index.as_retriever(..., similarity_top_k=2)
# OR
index.as_query_engine(..., similarity_top_k=2)
# OR
index.as_chat_engine(..., similarity_top_k=2)
Works well. Thank you!
Add a reply
Sign up and join the conversation on Discord