File size: 1,684 Bytes
249fca7
23a84f2
85952ea
d967c00
23a84f2
a3e054f
 
 
 
23a84f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d967c00
23a84f2
 
1d2c336
23a84f2
 
 
 
 
 
 
 
 
1d2c336
 
 
 
 
85952ea
 
 
 
23a84f2
85952ea
 
23a84f2
 
 
 
 
d3e2171
1d2c336
 
23a84f2
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
53
54
55
56
57
58
59
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
from langchain_community.vectorstores import Pinecone
from langchain_community.vectorstores.utils import DistanceStrategy
from langchain_openai import ChatOpenAI
from pinecone import Pinecone as PineconeClient
import streamlit as st

st.set_page_config(layout="wide", page_title="LegisQA")


CONGRESS_GOV_TYPE_MAP = {
    "hconres": "house-concurrent-resolution",
    "hjres": "house-joint-resolution",
    "hr": "house-bill",
    "hres": "house-resolution",
    "s": "senate-bill",
    "sconres": "senate-concurrent-resolution",
    "sjres": "senate-joint-resolution",
    "sres": "senate-resolution",
}

OPENAI_CHAT_MODELS = [
    "gpt-3.5-turbo-0125",
    "gpt-4-0125-preview",
]


def load_bge_embeddings():
    model_name = "BAAI/bge-small-en-v1.5"
    model_kwargs = {"device": "cpu"}
    encode_kwargs = {"normalize_embeddings": True}
    emb_fn = HuggingFaceBgeEmbeddings(
        model_name=model_name,
        model_kwargs=model_kwargs,
        encode_kwargs=encode_kwargs,
        query_instruction="Represent this question for searching relevant passages: ",
    )
    return emb_fn


def load_pinecone_vectorstore():
    emb_fn = load_bge_embeddings()
    pc = PineconeClient(api_key=st.secrets["pinecone_api_key"])
    index = pc.Index(st.secrets["pinecone_index_name"])
    vectorstore = Pinecone(
        index=index,
        embedding=emb_fn,
        text_key="text",
        distance_strategy=DistanceStrategy.COSINE,
    )
    return vectorstore



vectorstore = load_pinecone_vectorstore()
query = st.text_area("Enter query")
docs = vectorstore.similarity_search_with_score(query)
st.write(docs)