So, if you're using a query_engine, the source nodes that come back in the response have a field called score that is the cosine similarity (Default setting) of your query embedding and the node's doc embedding.
Oh maybe I am misunderstanding. Can you kindly elaborate on what you mean by "if rag fails". The RAG system uses cosine similarity by default to find the most relevant documents to the query.