llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

Get cosine score while querying index

Open abhishek22-ai opened this issue 3 years ago • 2 comments

Hi, Is there a way to overload or method available for index.query method to get the cosine score as well ?

abhishek22-ai avatar Feb 17 '23 07:02 abhishek22-ai

You can get the source_nodes from the response object and it will include the similarity score. Is this what you're looking for?

ymansurozer avatar Feb 17 '23 16:02 ymansurozer

yep! exactly what @ymansurozer mentioned.

jerryjliu avatar Feb 17 '23 17:02 jerryjliu

@ymansurozer is it possible to query these source nodes without the call to the LLM? If I'm just using the response.source_nodes, I dont want the query function to waste time and resources.

rhelsing avatar Feb 19 '23 21:02 rhelsing

yeah just set response_mode="no_text" during the index.query call

jerryjliu avatar Feb 19 '23 21:02 jerryjliu

@jerryjliu Thank you!

rhelsing avatar Feb 19 '23 21:02 rhelsing

going to close this issue for now since seems resolved

jerryjliu avatar Feb 19 '23 21:02 jerryjliu

@ymansurozer Thanks, I used the same method as you described but the source_nodes object has similarity=None ?

cc: @jerryjliu

abhishek22-ai avatar Feb 20 '23 05:02 abhishek22-ai

@abhishek22-ai can you share your code?

ymansurozer avatar Feb 20 '23 07:02 ymansurozer

Is there a way to do similarity search without querying index ? For eg: I have ListIndex with text and embeddings I have query_str with its embeddings Now, I just want to get the cosine score between query_str and ListIndex ?

abhishek22-ai avatar Feb 20 '23 07:02 abhishek22-ai

yes see above https://github.com/jerryjliu/gpt_index/issues/466#issuecomment-1436096393

jerryjliu avatar Feb 20 '23 07:02 jerryjliu

@jerryjliu Hi, What might be reason behind getting similarity=None in response object ? Thanks

abhishek22-ai avatar Feb 20 '23 07:02 abhishek22-ai