You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched both the documentation and discord for an answer.
Question
save to disk
from dotenv import load_dotenv
load_dotenv()
from chromadb import Settings
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores import ChromaVectorStore
from llama_index.storage.storage_context import StorageContext
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from llama_index.embeddings import LangchainEmbedding
from IPython.display import Markdown, display
import chromadb
Question Validation
Question
save to disk
from dotenv import load_dotenv
load_dotenv()
from chromadb import Settings
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores import ChromaVectorStore
from llama_index.storage.storage_context import StorageContext
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from llama_index.embeddings import LangchainEmbedding
from IPython.display import Markdown, display
import chromadb
set up OpenAI
import os
import getpass
create client and a new collection
chroma_client = chromadb.Client()
chroma_collection = chroma_client.create_collection("quickstart")
print(chroma_collection.count())
define embedding function
embed_model = LangchainEmbedding(
HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
)
load documents
documents = SimpleDirectoryReader(
"news"
).load_data()
print(documents)
set up ChromaVectorStore and load in data
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context, embed_model=embed_model
)
print(index)
print(chroma_collection.count())
print(chroma_collection.get()['documents'])
print(chroma_collection.get()['metadatas'])
Query Data
query_engine = index.as_query_engine(chroma_collection=chroma_collection)
response = query_engine.query("中国最近发生了什么,说出发生的时间?")
print(response)
display(Markdown(f"{response}"))
OUTPUTS:
F:\Anaconda\python.exe D:\EmbeddingsSearch\Chroma_Search\test.py
0
<llama_index.indices.vector_store.base.VectorStoreIndex object at 0x00000210F8D88E50>
77
中国最近发生了2022年11月末,中国北京、上海、南京、广州、成都、重庆等多个城市爆发了大批年轻人抗议所谓“动态清零”极端防疫政策的白纸运动,以及武汉、大连、鞍山等地出现了大批退休人员上街抗议医保福利削减的“白发运动”,以及中共领导人反复强调安全,以及达赖喇嘛称北京方面有意与他接触,他对恢复对话没有任何问题,发生的时间是2022年11月末至2023年7月10日。
<IPython.core.display.Markdown object>
Process finished with exit code 0
The text was updated successfully, but these errors were encountered: