跳转到内容

加载文档

documents = SimpleDirectoryReader(”./data/paul_graham/“).load_data() print(“文档ID:”, len(documents), documents[0].doc_id)

Document ID: 1 8d84aefd-ca73-4c1e-b83d-141c1b1b3ba6
```python
from llama_index import ServiceContext
from llama_index.embeddings import HuggingFaceEmbedding
from llama_index.vector_stores import VearchVectorStore
"""
vearch cluster
"""
vector_store = VearchVectorStore(
path_or_url="http://liama-index-router.vectorbase.svc.sq01.n.jd.local",
table_name="liama_index_test2",
db_name="liama_index",
flag=1,
)
"""
vearch standalone
"""
# vector_store = VearchVectorStore(
# path_or_url = '/data/zhx/zhx/liama_index/knowledge_base/liama_index_teststandalone',
# # path_or_url = 'http://liama-index-router.vectorbase.svc.sq01.n.jd.local',
# table_name = 'liama_index_teststandalone',
# db_name = 'liama_index',
# flag = 0)
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
service_context = ServiceContext.from_defaults(embed_model=embed_model)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context, service_context=service_context
)
Loading checkpoint shards: 0%| | 0/7 [00:00<?, ?it/s]
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))

作者未提供任何关于其成长经历的信息。

query_engine = index.as_query_engine()
response = query_engine.query(
"What did the author do after his time at Y Combinator?"
)
display(Markdown(f"<b>{response}</b>"))

作者在继续为Y Combinator工作的同时,用Arc语言编写了Y Combinator的所有内部软件,但后来停止开发Arc,专注于撰写文章和Y Combinator的工作。2012年,作者的母亲中风,作者意识到Y Combinator占用太多时间,决定将其移交他人。作者向Robert Morris提出这个想法,对方主动建议作者要确保Y Combinator不会成为作者做的最后一件酷事。作者最终于2013年决定将Y Combinator的领导权移交给Sam Altman。