Closed RayceRossum closed 11 months ago
@RayceRossum Thanks your feedback. And i will try to fix it
@RayceRossum the 0.1.39 has been released, and you can try it. Looking forward to your feedback.
@SimFG, this is still broken. I believe it is backwards. id should be res_data[1], right now you have res_data[0] as the id.
).order_by(
similarity
).limit(top_k).all()
search_result = [(r[0].id, r[1]) for r in search_result]
return search_result
I've tested this on my end and lookup seems to be working correctly aside from now running into this issue with langchain generating Generation instead of ChatGeneration when using GPTCache and then putting those Generations into a ChatResult when it should be using ChatGenerations into a ChatResult.
@RayceRossum I'm so sorry. It was my carelessness.
@RayceRossum I have fixed it. Thanks your feedback, and i will close the issue.
When using gptcache w/ langchain, postgresql and pgvector. I'm running into an issue where the correct answer is being found, but the search in the data manager is looking up the data by the distance (0.0) instead of looking up the id.
res_data is passed into the data managers get_scalar_data as a
<class 'sqlalchemy.engine.row.Row'>
containing:(<gptcache.manager.vector_data.pgvector._get_model_and_index.<locals>.VectorStoreTable object at 0x7f917a4f2ce0>, 0.0)
get_scalar_data uses res_data[1] which is representing the added distances column value from the previous search_data step in the adapter, not the id.
cache_data = self.s.get_data_by_id(res_data[1[)
https://github.com/zilliztech/GPTCache/blob/8f7d36a97ca5cd55930a73323ea67c6fbd607e4f/gptcache/manager/data_manager.py#L341C56-L341C56A simple fix that shows the correct answer in my debugger is:
cache_data = self.s.get_data_by_id(res_data[0].id)
but I imagine this has additional impacts so likely there is something that needs to be done with the search function for pgvector
UPDATE: Taking a quick look, I can see faiss returns
return list(zip(dist[0], ids))
from itssearch
function, which makes sense whereas the pgvectorsearch
function doesn't quite lineup. Likely just an edit here is needed to match up the formatshttps://github.com/zilliztech/GPTCache/blob/8f7d36a97ca5cd55930a73323ea67c6fbd607e4f/gptcache/manager/vector_data/pgvector.py#L145