建立向量索引
我們 Line 節點上的 'text' 屬性,非常適合用來產生嵌入向量,以回應關於這齣劇本的開放式問題。
使用 langchain-neo4j 提供的向量儲存元件,為 Line 節點的 'text' 屬性建立向量索引。
本練習屬於課程
使用 LangChain 與 Neo4j 的 Graph RAG
練習說明
- 使用正確的類別,從既有的節點與關係圖中建立向量索引。
- 指示該類別將嵌入向量儲存在
'embedding'節點屬性中。 - 指示該類別針對
'text'節點屬性建立嵌入向量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from langchain_neo4j import Neo4jVector
# Create a vector store from the existing graph
line_retriever = ____.from_existing_graph(
embedding=embeddings,
url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD,
index_name="lines_index",
node_label="Line",
# Set the embedding and text node properties
____="embedding",
____=["text"],
)
results = line_retriever.similarity_search_with_score("Biting a finger", k=3)
for result in results:
print(result[0].page_content)