Skip to main content

Graph retrieval

Project description

GraphRetrieval

GraphRetrieval is a Python library designed for advanced text retrieval and knowledge graph querying. It supports various models and techniques to enable efficient and accurate information retrieval from large text corpora and knowledge bases.

Installation

pip install -e git+https://github.com/jayavibhavnk/GraphRetrieval.git#egg=GraphRetrieval

or

pip install GraphRetrieval

Usage Setting Up Environment Variables

Before using the library, set up the necessary environment variables for Neo4j and OpenAI:

import os

os.environ["NEO4J_URI"] = "add your Neo4j URI here"
os.environ["NEO4J_USERNAME"] = "add your Neo4j username here"
os.environ["NEO4J_PASSWORD"] = "add your Neo4j password here"
os.environ['OPENAI_API_KEY'] = "add your OpenAI API key here"

GraphRAG

GraphRAG is used to create and query graphs based on text documents.

Example

import GraphRetrieval
from GraphRetrieval import GraphRAG

grag = GraphRAG()
grag.create_graph_from_file('add file path here')

# Query using the default A* search
print(grag.queryLLM("Ask your query here")) 

# Switch to greedy search
grag.retrieval_model = "greedy"
print(grag.queryLLM("Ask your query here"))

KnowledgeRAG

KnowledgeRAG integrates with a knowledge graph and supports hybrid searches combining structured and unstructured data.

Example

from GraphRetrieval import KnowledgeRAG
from langchain_community.graphs import Neo4jGraph

graph = Neo4jGraph()
gr = KnowledgeRAG()

# Initialize graph
gr.init_graph(graph)

# Create the graph chain
gchain = gr.graphChain()

# Query the graph chain
print(gchain.invoke({"question": "Ask your query here"}))

# Hybrid search using Neo4j vector index
gr.init_neo4j_vector_index()
gr.hybrid = True
print(gchain.invoke({"question": "Ask your query here"}))

Ingesting Data into Graph

Ingest large text data into the knowledge graph.

text = "enter text here"

from langchain_text_splitters import CharacterTextSplitter

text_splitter = CharacterTextSplitter(
    separator="

",
    chunk_size=1000,
    chunk_overlap=200,
    length_function=len,
    is_separator_regex=False,
)

docs1 = text_splitter.create_documents([text])
docs = gr.generate_graph_from_text(docs1)
gr.ingest_data_into_graph(docs)

gr.init_neo4j_vector_index()
print(gchain.invoke({"question": "Ask your query here"}))

Hybrid Search with GraphRetrieval and Knowledge Base

Combine GraphRAG and KnowledgeRAG for hybrid search.

gr.vector_index = grag
gr.hybrid = True
print(gchain.invoke({"question": "Ask your query here"}))

Image Graph RAG

Use directories of images for searching similar images.

image_graph_rag = ImageGraphRAG()
image_paths = image_graph_rag.create_graph_from_directory('/content/images')
similar_images = image_graph_rag.similarity_search('/content/images/car.jpg', k=5)

for doc in similar_images:
    print(doc.metadata["path"])
image_graph_rag.visualize_graph() # for graph visualization

Note: This is a new version without parallelization, use 0.1.5>= for parallelization.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss what you would like to change. License

This project is licensed under the MIT License. See the LICENSE file for details.

This README.md provides an overview of the GraphRetrieval library, installation instructions, and example usage scenarios, with the specified changes to the file path and environment variables sections.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphretrieval-0.1.6.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

GraphRetrieval-0.1.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file graphretrieval-0.1.6.tar.gz.

File metadata

  • Download URL: graphretrieval-0.1.6.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for graphretrieval-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6af960edda80bbbf67607056cc4cfb08d8f1a90927690ae630697c3bbc368e61
MD5 9ba6e19260927553cad9c73da10808f4
BLAKE2b-256 de50e23baa05db1d1b20b9759f3c31a92cdae4c5b6a0fd66459bfe844398d0fe

See more details on using hashes here.

File details

Details for the file GraphRetrieval-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for GraphRetrieval-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bdd0ac8a1d216dcae0f7c5205bcbba04f7c8b98c2117d8b667be62e68664c89f
MD5 5003519103ea4b356af41d29ec2f2ada
BLAKE2b-256 15584205598fe5e4b75570cb30e71430ddf5db3de6cb338ebbeed6ca75c8aee3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page