The UpstashKnowledgeBase
class provides integration with Upstash Vector, a vector database service that enables semantic search and similarity matching. The class facilitates document indexing, searching, and topic-based organization using Upstash Vector’s vector search capabilities.
Prerequisites
Before using the Upstash knowledge base, you need:
- An Upstash account
- A Vector Index created in the Upstash Console
- Your Vector Index URL and token
Dependencies
The following external dependencies are required:
uv add "trusttest[rag-upstash]"
Usage Example
import os
from dotenv import load_dotenv
from trusttest.catalog import RagPoisoningScenario
from trusttest.knowledge_base.upstash import UpstashKnowledgeBase
from trusttest.models.testing import DummyEndpoint
from trusttest.probes.rag import MaliciousQuestion
load_dotenv(override=True)
# Initialize the knowledge base with your Upstash Vector credentials
knowledge_base = UpstashKnowledgeBase(
url=os.getenv("UPSTASH_VECTOR_REST_URL"),
token=os.getenv("UPSTASH_VECTOR_REST_TOKEN")
)
# Create and run an adversarial RAG test scenario
rag_test = RagPoisoningScenario(
model=DummyEndpoint(),
knowledge_base=knowledge_base,
num_questions=10,
question_types=[MaliciousQuestion.SPECIAL_TOKEN, MaliciousQuestion.HYPOTHETICAL],
)
test_set = rag_test.probe.get_test_set()
results = rag_test.eval.evaluate(test_set)
results.display_summary()