LlamaIndex VectorStoreIndex Query is not working - index.as_query_engine().query("Query string") call returns no results

I have following code , I am using LlamaIndex Vector search`` , my vector search query via LlamaIndex API is failing. Please see the error below

service_context = ServiceContext.from_defaults(embed_model=embed_model)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context,service_context=service_context
)
response = index.as_query_engine().query(“Query string”)

I am getting following error : OperationFailure: PlanExecutor error during aggregation :: caused by :: Error connecting to localhost:28000 (127.0.0.1:28000) :: caused by :: onInvoke :: caused by :: Connection refused, full error: {‘ok’: 0.0, ‘errmsg’: ‘PlanExecutor error during aggregation :: caused by :: Error connecting to localhost:28000 (127.0.0.1:28000) :: caused by :: onInvoke :: caused by :: Connection refused’, ‘code’: 6, ‘codeName’: ‘HostUnreachable’, ‘$clusterTime’: {‘clusterTime’: Timestamp(1708018066, 1), ‘signature’: {‘hash’: b"\xb4\xa2\xf9\xfc>U’\x82\r\x06v\xeb\x83r>\x99\x90\xb1\x98$", ‘keyId’: 7334758570434494470}}, ‘operationTime’: Timestamp(1708018066, 1)}

Hi Roofi,

From your error log seems like you don’t have access to 127.0.0.1:2800. Things to test:

  • is the server running in that IP address and port? Check that connecting from MongoDB Compass for instance.
  • is the server running in a container, installed directly? If in a container, share the config file for that container.

Thanks Diego for the response. I dont have any server running. I read following post Connection refused when using text search - MongoDB Atlas / Atlas Search - MongoDB Developer Community Forums

Created vector_index for my collection and the error went away. But I am unable to search Vector Index via LlamaIndex API : response = index.as_query_engine().query(“query string”) returns empty response. This seems be a bug in LlamaIndex API or mongodb LlamaIndex API

Hi @Roofi_Shaikh1,

Could you please verify in your database that you have successfully created your vector_index in your MongoDB collections? Also, please share the version of LlamaIndex you are using, along with the code snippet, so the community can assist you better.

Regards,
Kushagraa

Hi @Roofi_Shaikh1 you can access a working tutorial for LlamaIndex here - https://github.com/prakul/MongoDB-AI-Resources/blob/main/llamaIndex%2BmongoDB_MetadataFiltering.ipynb