askeco / app.py
gofeco's picture
Update app.py
7518e4e verified
raw
history blame
949 Bytes
from langchain.text_splitter import CharacterTextSplitter
from langchain_community.document_loaders import TextLoader
from langchain_community.document_loaders import DirectoryLoader
from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings
from langchain_community.vectorstores import Chroma
import streamlit as st
embedding_function = SentenceTransformerEmbeddings(model_name="all-mpnet-base-v2")
chdb = Chroma(persist_directory="./chroma_db_info", embedding_function=embedding_function)
query = st.text_input("Enter a query")
disnum = 3
if query:
docs = chdb.similarity_search_with_score(query)
docnum = len(docs)
index = 0
ret = f"Query:{query}\n"
for ii in range(docnum):
doc = docs[ii][0]
score = docs[ii][1]
ret += f"Return {index} ({score:.4f}) :\n{doc.page_content}\n"
index += 1
if index > disnum:
break
st.text(ret)