このページは、まだ日本語ではご利用いただけません。翻訳中です。
古いプラグインバージョンのドキュメントを閲覧しています。
Prerequisites
- OpenAI account and subscription
- Redis configured as a vector database
- Redis configured as a cache
- A service and a route for the LLM provider. You need a service to contain the route for the LLM provider. Create a service first:
curl -X POST http://localhost:8001/services \ --data "name=ai-semantic-cache" \ --data "url=http://localhost:32000"Remember that the upstream URL can point anywhere empty, as it won’t be used by the plugin.
Then, create a route:
curl -X POST http://localhost:8001/services/ai-semantic-cache/routes \ --data "name=openai-semantic-cache" \ --data "paths[]=~/openai-semantic-cache$"
OpenAI Example
This configures the following:
-
embeddings.auth.header_value: The API key for OpenAI. This uses OpenAI’s API Key explicitly, but you can use an environment variable instead if you want. -
model.provider: The model provider you want to use. In this example, OpenAI. -
model.name: The AI model to use for generating embeddings. This example is configured withtext-embedding-3-large, but you can also choosetext-embedding-3-smallfor OpenAI. -
model.options.upstream_url: The upstream URL for the LLM provider. -
vectordb.dimensions: The dimensionality for the vectors. Since this example usestext-embedding-3-large, OpenAI uses3072as the default embedding dimension. -
vectordb.distance_metric: The distance metric to use for vectors. This example usescosinebecause OpenAI recommends it. -
vectordb.strategy: Defines the vector database, in this case, Redis. -
vectordb.threshold: Defines the similarity threshold for accepting semantic search results. In the example, this is configured to as a low threshold, meaning it would include results that are only somewhat similar. -
vectordb.redis.host: The host of your vector database. -
vectordb.redis.port: The port to use for your vector database. -
config.embeddings.name: The AI model to use for generating embeddings. This example is configured withtext-embedding-3-large, but you can also choosetext-embedding-3-smallfor OpenAI.
This uses OpenAI’s API Key explicitly, but you can use an environment variable instead if you want.
More information
- Redis Documentation: Vectors - Learn how to use vector fields and perform vector searches in Redis
- Redis Documentation: How to Perform Vector Similarity Search Using Redis in NodeJS