RAG Service¶
Overview¶
The RagService implements a multi-step retrieval-augmented generation pipeline that connects language models with document context to provide context-aware AI responses.
Dependencies¶
LangchainService: For language model interactionPineconeService: For vector database operations
Key Methods¶
initializeQA¶
public async initializeQA(
llm: BaseChatModel,
db: PineconeStore,
k: number,
type?: string,
themesList?: string[]
)
Initializes the RAG pipeline with: - Question-condensing chain to rewrite user queries - Document retrieval from vector store - Answer generation with document context
Parameters:
- llm: Language model to use
- db: Pinecone vector store
- k: Number of documents to retrieve
- type: Optional response type
- themesList: Optional themes for filtering
getAnswer¶
async getAnswer(
vectorStore: PineconeStore,
query: string,
lengthType: 'short' | 'long' = 'short',
themes: string[] = [],
language: string = 'english-uk'
): Promise<string>
Processes a query and returns a context-aware answer.
Parameters:
- vectorStore: Pinecone vector store
- query: User question
- lengthType: Response length preference
- themes: Optional themes for filtering
- language: Response language
Returns: - String containing the generated answer
addDocumentToVectorStore¶
Adds a document to the vector store: - Converts base64 document to text - Processes and adds document to vector store
Parameters:
- documentBase64: Base64-encoded document
- userId: User identifier