This package contains a test function that demonstrates the usage of various components for retrieving and processing information from a vector store.
- context
- fmt
- log
- os
- strings
- testing
- embd
- embeddings
- godotenv
- langchaingo/chains
- langchaingo/llms/openai
- langchaingo/vectorstores
- .env file: Contains environment variables for AI endpoint, API token, database URL, and namespace.
-
Test_main function:
- Loads environment variables from the .env file.
- Retrieves values for AI endpoint, API token, database URL, and namespace from the environment variables.
- Defines a list of repository names and test prompts.
- Calls the
generateResponse
function for each test prompt and repository name.
-
getCollection function:
- Takes AI endpoint, API token, database URL, and namespace as input.
- Uses the
embd.GetVectorStoreWithOptions
function to retrieve a vector store from the specified parameters. - Returns the vector store and any error encountered.
-
generateResponse function:
- Takes a prompt and namespace as input.
- Calls the
getCollection
function to retrieve a vector store for the given namespace. - Performs semantic search using the retrieved vector store and the provided prompt.
- Constructs a context string by concatenating the page content of the retrieved documents.
- Calls the
rag
function to generate a response using the context and prompt. - Returns the generated response and any error encountered.
-
rag function:
- Takes a question, AI endpoint, API token, number of results, and vector store as input.
- Creates an embeddings client using the specified API and embedding model.
- Performs semantic search using the vector store and the provided question.
- Constructs a full prompt by combining the context and question.
- Calls the
chains.Run
function to generate a response using the retrieved context, question, and embeddings client. - Returns the generated response and any error encountered.