{"id":22455003,"url":"https://github.com/rajaniraiyn/semantic_cache","last_synced_at":"2025-10-12T01:23:31.979Z","repository":{"id":231132517,"uuid":"780999146","full_name":"Rajaniraiyn/semantic_cache","owner":"Rajaniraiyn","description":"Semantic caching for Python Functions","archived":false,"fork":false,"pushed_at":"2024-04-02T18:05:04.000Z","size":12,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-19T03:59:47.247Z","etag":null,"topics":["caching","decorators-python","embeddings","in-memory-caching","llm","python","semantic-search","verctor-retrieval"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rajaniraiyn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-02T15:02:58.000Z","updated_at":"2025-01-03T19:51:09.000Z","dependencies_parsed_at":"2024-04-02T16:46:00.937Z","dependency_job_id":"cf641a82-f856-4ecc-82bc-8a732689a133","html_url":"https://github.com/Rajaniraiyn/semantic_cache","commit_stats":null,"previous_names":["rajaniraiyn/semantic_cache"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Rajaniraiyn/semantic_cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rajaniraiyn%2Fsemantic_cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rajaniraiyn%2Fsemantic_cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rajaniraiyn%2Fsemantic_cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rajaniraiyn%2Fsemantic_cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rajaniraiyn","download_url":"https://codeload.github.com/Rajaniraiyn/semantic_cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rajaniraiyn%2Fsemantic_cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009755,"owners_count":26084645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","decorators-python","embeddings","in-memory-caching","llm","python","semantic-search","verctor-retrieval"],"created_at":"2024-12-06T07:09:48.030Z","updated_at":"2025-10-12T01:23:31.961Z","avatar_url":"https://github.com/Rajaniraiyn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# `semantic-cache`: Semantic Caching for Python Functions\n\n\u003c/div\u003e\n\nThis project provides a decorator for Python functions that implements semantic caching. This means that function calls with semantically similar inputs will return the cached result, even if the exact input values are different. This can be useful for optimizing expensive function calls, especially when dealing with natural language processing or other tasks where inputs can vary slightly but still have the same meaning.\n\n## How it works\n\nThe semantic_cache decorator uses the Qdrant vector similarity search engine to store and retrieve function call information. When a function is decorated, the following happens:\n\n1. **Input encoding:** The function arguments and keyword arguments are converted into a string representation.\n2. **Similarity search:** This string representation is used to query Qdrant for similar previously cached function calls.\n3. **Cache hit:** If a similar call is found with a similarity score above a threshold (default 0.95), the cached result is returned.\n4. **Cache miss:** If no similar call is found, the function is executed, its output is stored in the cache along with the input representation, and the output is returned.\n\n## Installation\n\n```sh\npip install semantic-cache\n```\n\n## Usage\n\n```py\nfrom semantic_cache import semantic_cache\n\n@semantic_cache()\ndef say(message: str) -\u003e str:\n    return f\"Hi {message}\"\n\n# First call, function is executed\nresult1 = say(\"John\")\n\n# Second call with semantically similar input, cached result is used\nresult2 = say(\"john\")\n\nassert result1 == result2\n```\n\n## Features\n\n- **Similarity threshold:** You can adjust the similarity threshold for determining cache hits.\n- **In-memory caching:** By default, an in-memory Qdrant instance is used for caching. You can configure a persistent Qdrant server for production use.\n- **Automatic input encoding:** The decorator automatically handles the conversion of function arguments into a searchable representation.\n\n## Potential Applications\n\n- **Natural language processing:** Cache results for functions that process text inputs, even if the wording is slightly different.\n- **Machine learning model inference:** Optimize inference calls by caching results for similar input data points.\n- **Expensive calculations:** Cache the results of computationally intensive functions based on input parameters.\n\n## Contributing\n\nContributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajaniraiyn%2Fsemantic_cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajaniraiyn%2Fsemantic_cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajaniraiyn%2Fsemantic_cache/lists"}