Jan 01, 1970
ከምኡ ኢልና ተኻቲዕና ኢና።
ሰነዳት ናብ ከም Neo4j ዝኣመሰለ ኣካል ማእከል ዝገበረ ግራፍ ስቶር ምጽዓን ናይ LangChain LLMGraphTransformer ተጠቒምካ እዩ ተኻይዱ። እቲ ኮድ ኣብ LangChain's ዝተመርኮሰ እዩ።
from langchain_core.documents import Document from langchain_experimental.graph_transformers import LLMGraphTransformer from langchain_openai import ChatOpenAI llm = ChatOpenAI(temperature=0, model_name="gpt-4-turbo") llm_transformer = LLMGraphTransformer(llm=llm) from time import perf_counter start = perf_counter() documents_to_load = [Document(page_content=line) for line in lines_to_load] graph_documents = llm_transformer.convert_to_graph_documents(documents_to_load) end = perf_counter() print(f"Loaded (but NOT written) {NUM_LINES_TO_LOAD} in {end - start:0.2f}s")
import json from langchain_core.graph_vectorstores.links import METADATA_LINKS_KEY, Link def parse_document(line: str) -> Document: para = json.loads(line) id = para["id"] links = { Link.outgoing(kind="href", tag=id) for m in para["mentions"] if m["ref_ids"] is not None for id in m["ref_ids"] } links.add(Link.incoming(kind="href", tag=id)) return Document( id = id, page_content = " ".join(para["sentences"]), metadata = { "content_id": para["id"], METADATA_LINKS_KEY: list(links) }, )
from langchain_openai import OpenAIEmbeddings from langchain_community.graph_vectorstores.cassandra import CassandraGraphVectorStore import cassio cassio.init(auto=True) TABLE_NAME = "wiki_load" store = CassandraGraphVectorStore( embedding = OpenAIEmbeddings(), node_table=TABLE_NAME, insert_timeout = 1000.0, ) from time import perf_counter start = perf_counter() from datasets.wikimultihop.load import parse_document kg_documents = [parse_document(line) for line in lines_to_load] store.add_documents(kg_documents) end = perf_counter() print(f"Loaded (and written) {NUM_LINES_TO_LOAD} in {end - start:0.2f}s")
ታሕተዋይ መስመር፡ እቲ ኣካል ማእከል ዝገበረ ኣገባብ፡ LLM ተጠቒምካ ካብ ትሕዝቶ ናይ ፍልጠት ግራፍ ምውጻእ፡ ብመጠን ግዜን ወጻኢታትን ዝኽልክል እዩ ነይሩ። ብኻልእ ወገን ድማ GraphVectorStore ምጥቃም ቅልጡፍን ርካሽን እዩ ነይሩ።
ኣካል ማእከል ዝገበረ 7324 ፕሮምፕት ቶከናት ተጠቒሙ ብመሰረቱ ዘይጠቅም መልስታት ንምፍራይ $0.03 ወጻኢታት ክጥቀም እንከሎ፡ ትሕዝቶ ማእከል ዝገበረ ድማ 450 ፕሮምፕት ቶከናት ተጠቒሙ፡ ብቐጥታ ንሕቶታት ዝምልስ ጽፉፍ መልሲ ንምፍራይ ድማ $0.002 ወጻኢታት ገይሩ።
> Entering new GraphCypherQAChain chain... Generated Cypher: cypher MATCH (a:Album {id: 'The Circle'})-[:RELEASED_BY]->(r:Record_label) RETURN a.id, r.id Full Context: [{'a.id': 'The Circle', 'r.id': 'Restless'}] > Finished chain. {'query': "When was 'The Circle' released?", 'result': "I don't know the answer."}
ግራፍ ራግ ንጀነሬቲቭ ኤኣይ ራግ ኣፕሊኬሽናት ዝያዳ ብዕምቆት ዝምልከቱ ዓውድታት ንምርካብ ዘኽእል ጠቓሚ መሳርሒ እዩ። ረቂቕ እኽሊ ዘለዎ፡ ኣካል ማእከል ዝገበረ ኣገባብ ምጥቃም ግን ምስ ድሌታት ምፍራይ ኣይመጣጠንን እዩ። ኣብ ናይ RAG መተግበሪኻ ናይ ፍልጠት ግራፍ ዓቕሚ ክትውስኽ ትደሊ እንተኾንካ፡ ፈትን።