Sometimes you have usescases where you need to fetch multiple deployed prompt chains at once using a single query. For example, you might want to fetch all prompts for a specific customer or specific workflow. You can use getPromptChains function for this purpose.
You will need to query using at-least one deploymentVar as a filter. Hence you will need to deploy prompt chain versions before querying
them.
Maxim SDK uses in-memory caching by default. You can use your own caching implementation by passing a custom cache object to the SDK. This allows you to remove complete dependency on our backend.
Before going into the details of how to use the SDK, let's understand how the matching algorithm works. Maxim SDK uses best matching entity algorithm.
Let's assume that, you have asked for a prompt chain with deployment var env as prod, customerId as "123" and a tag, tenantId as 456 for promptId - "abc".
SDK will first try to find a prompt chain matching all conditions.
If we don't find any matching entity, we enforce only deploymentVar conditions (you can override this behaviour, as explained in the next section) and match as many tags as possible.
If we still don't find any prompt chain, we check for a prompt chain version marked as fallback.
If we still don't find any prompt chain, we return null.
You can override fallback algorithm by calling .exactMatch() on QueryBuilder object. That will enforce all conditions to be matched.
import { QueryBuilder } from "@maximai/maxim-js;const promptChain = await maxim.getPromptChain( "prompt-chain-id", new QueryBuilder().and().deploymentVar("Environment", "prod").exactMatch().build(),);
You can override fallback algorithm at each variable level. The third optional parameter in deploymentVar & tag function is enforce. If you pass true to this parameter, it will enforce exact match for that variable.
import { Maxim, QueryBuilder } from "@maximai/maxim-js;const maxim = new Maxim({ apiKey: "" });const promptChain = await maxim.getPromptChain("prompt-id", new QueryBuilder().and().deploymentVar("Environment", "prod").build());