spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Add CLIENT SETNAME to Valkey vector store for connection identification

Open atao2004 opened this issue 6 months ago • 2 comments

Summary

The ValkeyVectorStore accepts a pre-built valkey-glide BaseClient and does not set a clientName. When the caller does not configure one, the connection appears anonymous in monitoring tools like CLIENT LIST and Valkey Admin.

Suggested Fix

In ValkeyVectorStore.java (line ~99), when the store creates its own client internally, set a default clientName:

GlideClientConfiguration config = GlideClientConfiguration.builder()
    .address(NodeAddress.builder().host(host).port(port).build())
    .clientName("spring_ai_vector_store_client")
    .build();

Why This Matters

When monitoring a Valkey server with multiple connected applications, CLIENT LIST shows each connection's name. Without a client name, operators cannot distinguish Spring AI connections from other anonymous clients. This is especially important in production environments with ElastiCache where multiple services share the same Valkey cluster.

Setting clientName sends a CLIENT SETNAME command on connection, making the connection identifiable in:

  • CLIENT LIST output
  • Monitoring dashboards (e.g., Valkey Admin)
  • CloudWatch metrics (ElastiCache)

Naming Convention

Suggested client name: spring_ai_vector_store_client

Pattern: {project}_{purpose}_client

  • spring_ai = project name
  • vector_store = purpose (vector store for Spring AI RAG)
  • _client = convention (matches Valkey Admin naming pattern)

atao2004 avatar May 26 '26 21:05 atao2004

Thanks for opening this.

I took a look at the current state, and this appears to be tied to the Valkey vector store work in #5471 rather than main, since spring-ai-valkey-store is not present on main yet.

I also noticed that commit b171810 (feat: add client name) adds .clientName("spring_ai_vector_store_client") to the test GlideClientConfiguration instances, but it does not seem to change the production/client creation path.

If users pass a pre-built BaseClient into ValkeyVectorStore, the store cannot set the client name itself. And if the intended fix is for Spring AI-created clients, then the default client name likely needs to be applied wherever the production GlideClientConfiguration is built, not only in tests.

So I think the remaining question is:

Should spring_ai_vector_store_client be applied only to internally-created/default Valkey clients, while preserving user-provided BaseClient instances unchanged?

If so, I’d be happy to open a small follow-up patch against edlng:GH-5215 / #5471 to add the production-side default client name, probably as a constant such as DEFAULT_CLIENT_NAME, and keep user-provided clients untouched.

jyt6640 avatar May 28 '26 00:05 jyt6640

I opened a PR against the #5471 branch: https://github.com/edlng/spring-ai/pull/1

This issue appears to apply to the Valkey PR branch rather than main, since Valkey is not on main yet. Commit b171810 adds the client name for test-created clients; the follow-up patch applies the default spring_ai_vector_store_client name in the production auto-configuration path by creating the GlideClientConfiguration with that client name. It also keeps caller-provided BaseClient instances caller-owned and does not mutate them inside ValkeyVectorStore.

jyt6640 avatar May 28 '26 01:05 jyt6640