File size: 1,157 Bytes
bf6dbfa
 
 
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
 
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
0643073
 
 
bf6dbfa
 
 
0643073
bf6dbfa
 
 
 
 
0643073
 
bf6dbfa
0643073
 
bf6dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest
import os
from rag.vectorstore import build_vectorstore
import rag.vectorstore
from langchain_core.embeddings import Embeddings
from typing import List

os.environ["OPENAI_API_KEY"] = "dummy_key"

class MockEmbedding(Embeddings):
    def embed_documents(self, texts: List[str]) -> List[List[float]]:

        return [[0.0] * 1536 for _ in texts]

    def embed_query(self, text: str) -> List[float]:
        return [0.0] * 1536

def test_rag_pipeline_loads_and_retrieves(mocker, tmp_path):

    kb_file = tmp_path / "knowledge_base.md"
    kb_file.write_text("""
# AutoStream Pricing & Features

## Pro Plan
* $79/month
* Unlimited videos
* 4K resolution
* AI captions included
    """)


    mocker.patch('rag.vectorstore.get_embeddings', return_value=MockEmbedding())




    vs = build_vectorstore(str(kb_file))
    assert vs is not None


    mocker.patch('rag.retriever.get_vectorstore', return_value=vs)
    from rag.retriever import retrieve_documents

    docs = retrieve_documents("What does the Pro plan cost?", k=1)



    assert len(docs) > 0


    assert "AutoStream" in docs[0] or "Pro Plan" in docs[0] or "$79/month" in docs[0]