Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Custom ID on context caching vertex ai

Hi, community.

I'm trying to create a cached content in Vertex AI. I want to provide a custom ID to the endpoint. Is it possible?

My goal:
```py

async def achat(
        self, messages: Sequence[ChatMessage], **kwargs: Any
    ) -> ChatResponse:
        if self.cache_config["enabled"]:
            try:
                cached_content: caching.CachedContent = caching.CachedContent(
                    cached_content_name=self.cache_config["cache_id"],
                )
            except Exception:
                cached_content = caching.CachedContent.create(
                    model_name=self.model,
                    system_instruction=next(
                        filter(lambda x: x.role == MessageRole.SYSTEM, messages)
                    ),
                    display_name=self.cache_config["cache_id"],
                )

            model: GenerativeModel = GenerativeModel.from_cached_content(
                cached_content=cached_content
            )

            raise RuntimeError("Testing cached content. Model almost instantiated")
        else:
            model = GenerativeModel(model_name=self.model)

```

 

Users will provide custom IDs to the cached content, I'd like to be able to let the user control that

Solved Solved
0 2 301
1 ACCEPTED SOLUTION

Hi @arthurbrcuni,

Welcome to Google Cloud Community!

Using custom ID on context caching in Vertex AI is not yet possible. With this, I suggest to file this as a feature request so our engineering team can look into it. Please note that I can't provide any details or timelines at this moment. However, you may keep an eye on the release notes for any latest updates or new features related to Vertex AI.

Hope this helps.

View solution in original post

2 REPLIES 2

Hi @arthurbrcuni,

Welcome to Google Cloud Community!

Using custom ID on context caching in Vertex AI is not yet possible. With this, I suggest to file this as a feature request so our engineering team can look into it. Please note that I can't provide any details or timelines at this moment. However, you may keep an eye on the release notes for any latest updates or new features related to Vertex AI.

Hope this helps.

Thanks a lot, @cassandramae