Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
791 changes: 117 additions & 674 deletions README.md

Large diffs are not rendered by default.

229 changes: 138 additions & 91 deletions docs/FAQ.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PostgreSQL License

Copyright (c) 2024, Aqeel

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement
is hereby granted, provided that the above copyright notice and this
paragraph and the following two paragraphs appear in all copies.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
42 changes: 42 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Architecture

pg_semantic_cache is implemented in pure C using the PostgreSQL extension API
(PGXS), providing:

- Small binary size of ~100KB vs 2-5MB for Rust-based extensions.
- Fast build times of 10-30 seconds vs 2-5 minutes.
- Immediate compatibility works with new PostgreSQL versions immediately.
- Standard packaging is compatible with all PostgreSQL packaging tools.

## How It Works

```mermaid
graph LR
A[Query] --> B[Generate Embedding]
B --> C{Cache Lookup}
C -->|Hit| D[Return Cached Result]
C -->|Miss| E[Execute Query]
E --> F[Store Result + Embedding]
F --> G[Return Result]
```

1. Generate an embedding by converting your query text into a vector embedding
using your preferred model (OpenAI, Cohere, etc.).
2. Check the cache by searching for semantically similar cached queries using
cosine similarity.
3. On a cache hit, if a similar query exists above the similarity threshold,
the cached result is returned.
4. On a cache miss, the actual query is executed and the result is cached with
its embedding for future use.
5. Automatic maintenance evicts expired entries based on TTL and configured
policies.


## Getting Help

- Browse the documentation.
- Report issues at
[GitHub Issues](https://github.com/pgedge/pg_semantic_cache/issues).
- See [Use Cases](use_cases.md) for practical implementation examples.
- Check the [FAQ](FAQ.md) for answers to common questions.

Loading