Commit
·
860dbdf
1
Parent(s):
d368963
test refactor: Add basic support to Index from vector store
Browse files- chatbot_server.py +11 -2
chatbot_server.py
CHANGED
@@ -58,10 +58,17 @@ import chromadb
|
|
58 |
db = chromadb.PersistentClient(path="chroma_db")
|
59 |
chroma_collection = db.get_or_create_collection("dense_vectors")
|
60 |
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
|
|
61 |
storage_context = StorageContext.from_defaults(
|
62 |
docstore=docstore, vector_store=vector_store
|
63 |
)
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
storage_context.docstore.persist("./docstore.json")
|
67 |
|
@@ -70,7 +77,7 @@ import nest_asyncio
|
|
70 |
nest_asyncio.apply()
|
71 |
from llama_index.retrievers.bm25 import BM25Retriever
|
72 |
bm25_retriever = BM25Retriever.from_defaults(
|
73 |
-
docstore=
|
74 |
similarity_top_k=2,
|
75 |
language = "portuguese",
|
76 |
verbose=True,
|
@@ -106,6 +113,8 @@ chat_engine = CondensePlusContextChatEngine.from_defaults(
|
|
106 |
" Aqui estão os documentos relevantes para o contexto:\n"
|
107 |
"{context_str}"
|
108 |
"\nInstrução: Use o histórico da conversa anterior, ou o contexto acima, para responder."
|
|
|
|
|
109 |
),
|
110 |
)
|
111 |
|
|
|
58 |
db = chromadb.PersistentClient(path="chroma_db")
|
59 |
chroma_collection = db.get_or_create_collection("dense_vectors")
|
60 |
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
61 |
+
|
62 |
storage_context = StorageContext.from_defaults(
|
63 |
docstore=docstore, vector_store=vector_store
|
64 |
)
|
65 |
+
|
66 |
+
if db.list_collections():
|
67 |
+
index = VectorStoreIndex.from_vector_store(vector_store=vector_store, storage_context=storage_context, show_progress = True)
|
68 |
+
bm25_retriever_docstore = docstore
|
69 |
+
else:
|
70 |
+
index = VectorStoreIndex(nodes = nodes, storage_context=storage_context, show_progress = True)
|
71 |
+
bm25_retriever_docstore = index.docstore
|
72 |
|
73 |
storage_context.docstore.persist("./docstore.json")
|
74 |
|
|
|
77 |
nest_asyncio.apply()
|
78 |
from llama_index.retrievers.bm25 import BM25Retriever
|
79 |
bm25_retriever = BM25Retriever.from_defaults(
|
80 |
+
docstore=bm25_retriever_docstore,
|
81 |
similarity_top_k=2,
|
82 |
language = "portuguese",
|
83 |
verbose=True,
|
|
|
113 |
" Aqui estão os documentos relevantes para o contexto:\n"
|
114 |
"{context_str}"
|
115 |
"\nInstrução: Use o histórico da conversa anterior, ou o contexto acima, para responder."
|
116 |
+
"No final da resposta, depois de uma quebra de linha escreva o nome do documento que contém a informação entre dois ||, como ||Documento Nome||"
|
117 |
+
|
118 |
),
|
119 |
)
|
120 |
|