You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -40,27 +40,79 @@ curl -s -X POST "https://$HOST/v1/caches/$CACHE_ID/entires/search" \
40
40
This example uses `cURL` and Linux shell scripts to demonstrate the API; you can use any standard REST client or library.
41
41
{{% /info %}}
42
42
43
-
You can also use the [LangCache SDKs](#langcache-sdk) for Javascript and Python to access the API.
43
+
If your app is written in Python or Javascript, you can also use the LangCache Software Development Kits (SDKs) to access the API:
44
44
45
-
## API examples
45
+
-[LangCache SDK for Python](https://pypi.org/project/langcache/)
46
+
-[LangCache SDK for Javascript](https://www.npmjs.com/package/@redis-ai/langcache)
47
+
48
+
## Examples
46
49
47
50
### Search LangCache for similar responses
48
51
49
-
Use `POST /v1/caches/{cacheId}/entries/search` to search the cache for matching responses to a user prompt.
52
+
Use [`POST /v1/caches/{cacheId}/entries/search`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/search" >}}}) to search the cache for matching responses to a user prompt.
50
53
54
+
{{< multitabs id="search-basic"
55
+
tab1="REST API"
56
+
tab2="Python"
57
+
tab3="Javascript" >}}
51
58
```sh
52
59
POST https://[host]/v1/caches/{cacheId}/entries/search
Place this call in your client app right before you call your LLM's REST API. If LangCache returns a response, you can send that response back to the user instead of calling the LLM.
59
107
60
108
If LangCache does not return a response, you should call your LLM's REST API to generate a new response. After you get a response from the LLM, you can [store it in LangCache](#store-a-new-response-in-langcache) for future use.
61
109
62
-
You can also scope the responses returned from LangCache by adding an `attributes` object to the request. LangCache will only return responses that match the attributes you specify.
110
+
You can also scope the responses returned from LangCache by adding an `attributes` object to the request. LangCache will only return responses that match the attributes you specify.
63
111
112
+
{{< multitabs id="search-attributes"
113
+
tab1="REST API"
114
+
tab2="Python"
115
+
tab3="Javascript" >}}
64
116
```sh
65
117
POST https://[host]/v1/caches/{cacheId}/entries/search
66
118
{
@@ -70,10 +122,60 @@ POST https://[host]/v1/caches/{cacheId}/entries/search
Use `POST /v1/caches/{cacheId}/entries` to store a new response in the cache.
173
+
Use [`POST /v1/caches/{cacheId}/entries`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/set" >}}) to store a new response in the cache.
174
+
175
+
{{< multitabs id="store-basic"
176
+
tab1="REST API"
177
+
tab2="Python"
178
+
tab3="Javascript" >}}
77
179
78
180
```sh
79
181
POST https://[host]/v1/caches/{cacheId}/entries
@@ -83,10 +185,61 @@ POST https://[host]/v1/caches/{cacheId}/entries
Use `DELETE /v1/caches/{cacheId}/entries/{entryId}` to delete a cached response from the cache.
305
+
Use [`DELETE /v1/caches/{cacheId}/entries/{entryId}`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/delete" >}}) to delete a cached response from the cache.
res = lang_cache.delete_by_id(entry_id="{entryId}")
329
+
330
+
print(res)
331
+
```
332
+
333
+
-tab-sep-
334
+
335
+
```js
336
+
import { LangCache } from"@redis-ai/langcache";
337
+
338
+
constlangCache=newLangCache({
339
+
serverURL:"https://<host>",
340
+
cacheId:"<cacheId>",
341
+
serviceKey:"<LANGCACHE_SERVICE_KEY>",
342
+
});
343
+
344
+
asyncfunctionrun() {
345
+
constresult=awaitlangCache.deleteById({
346
+
entryId:"<entryId>",
347
+
});
104
348
105
-
You can also use `DELETE /v1/caches/{cacheId}/entries` to delete multiple cached responses at once. If you provide an `attributes` object, LangCache will delete all responses that match the attributes you specify.
349
+
console.log(result);
350
+
}
351
+
352
+
run();
353
+
```
354
+
355
+
{{< /multitabs >}}
356
+
357
+
You can also use [`DELETE /v1/caches/{cacheId}/entries`]({{< relref "/develop/ai/langcache/api-reference#tag/Cache-Entries/operation/deleteQuery" >}}) to delete multiple cached responses based on the `attributes` you specify. If you specify multiple `attributes`, LangCache will delete entries that contain all given attributes.
358
+
359
+
{{< warning >}}
360
+
If you do not specify any `attributes`, all responses in the cache will be deleted. This cannot be undone.
0 commit comments