Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some errors when i use milvus with GPTCache (cache : max_size) #633

Open
KimMinSang96 opened this issue Jul 15, 2024 · 1 comment
Open

Comments

@KimMinSang96
Copy link

I want to use gptcache with milvus. I have created the following code by referring to the example:

`data_manager = get_data_manager(CacheBase("sqlite"), 
                            VectorBase("milvus", 
                            dimension=onnx.dimension, 
                            index_params=MILVUS_INDEX_PARAMS,
                            search_params = SEARCH_PARAM[ann_type],
                            local_mode=False), 
                            max_size=100, 
                            clean_size=10)

cache.init(
embedding_func=onnx.to_embeddings,
data_manager=data_manager,
similarity_evaluation=SearchDistanceEvaluation(),
config=Config(similarity_threshold=0.9,
auto_flush=5
)
)This code is supposed to evict 10 out of 100 items when the number of queries exceeds 100, with a cache size of 100. However, I'm not sure if this is working correctly in milvus. For debugging, I added the following code to milvus.py:

def search(self, data: np.ndarray, top_k: int = -1):
    if top_k == -1:
        top_k = self.top_k
    search_result = self.col.search(
        data=data.reshape(1, -1).tolist(),
        anns_field="embedding",
        param=self.search_params,
        limit=top_k,
    )
    print(f"self.col.num_entities : {self.col.num_entities}")
    return list(zip(search_result[0].distances, search_result[0].ids))`

I added num_entities to check the size, and I found that it manages more than the cache size. Can you tell me why this is happening? Also, is there a way to make it work according to the cache_size?"
Is there anything specific you'd like me to explain or help with regarding this translated content?

@SimFG
Copy link
Collaborator

SimFG commented Jul 16, 2024

This is mainly because the num entity of milvus only obtains an approximate number of data rows, which is not accurate. If you need the exact number of rows, you need to call the query interface. You can refer to the milvus document: https://milvus.io/docs/get-and-scalar-query.md#Use-Advanced-Operators

res = client.query(
collection_name="collectin_name",
output_fields=["count(*)"]
)

For eviction, perhaps some explanations of another issue can deepen the understanding of this aspect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants