Skip to content

arca-research/nexus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nexus

nexus is a lightweight knowledge graph + vectorDB embedded library.

VERSION 0.1 

quickstart

git submodule add https://github.com/arca-research/nexus.git nexus
git submodule update --init --recursive
git commit -m "Add nexus submodule"
  1. download requirements.txt
  2. create .env and set OPENAI_API_KEY
  3. tune config.py to your liking

Below is a sample script main.py (note that here, main.py and nexus are at the same level)

from nexus import GraphBuilder, GraphQueryEngine, GraphIndex, GraphConfig
from dataclasses import dataclass
from pathlib import Path

@dataclass
class DocData:
    """Container for document information."""
    document_id: int
    filepath: Path | str

fp = "data/myfile.txt"

builder = GraphBuilder(debug=True)

# A) Building ---
# optional: see what the prompt looks like
with open(fp, "r", encoding="utf-8") as f:
    data = f.read()
print(builder._build_extraction_prompt(data))

# create the document container for the file
doc = DocData(document_id=0, filepath=fp)

# build() accepts list[DocLike] (defined in _schemas)
docs = [doc]

# build() will run LLM extraction and build a graph db in .nexus
builder.build(docs)

# B) Using the query engine ---
query_engine = GraphQueryEngine()
entities = query_engine.list_all_entities()
print(entities)

return # remove this when you're ready
ent = query_engine.Entity("<ENTITY>") # replace <ENTITY> with desired
print(ent.claims)

#  C) manually upserting aliases
cfg = GraphConfig()
index = GraphIndex(index_path=cfg.graph_index_path)
index.upsert_alias("FBI", "Federal Bureau of Investigation")

About

a lightweight knowledge engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published