-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated readme and example * updated readme index * updated assertion
- Loading branch information
Showing
10 changed files
with
494 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3' | ||
services: | ||
postgres: | ||
image: pgvector/pgvector:pg16 | ||
environment: | ||
- POSTGRES_USER=querent | ||
- POSTGRES_PASSWORD=querent | ||
- POSTGRES_DB=querent_test | ||
volumes: | ||
- ./quester/storage/sql/:/docker-entrypoint-initdb.d | ||
ports: | ||
- "5432:5432" | ||
networks: | ||
- querent | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready", "-d", "querent_test"] | ||
interval: 30s | ||
timeout: 60s | ||
retries: 5 | ||
start_period: 80s | ||
|
||
networks: | ||
querent: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import asyncio | ||
from asyncio import Queue | ||
import json | ||
from pathlib import Path | ||
from querent.callback.event_callback_interface import EventCallbackInterface | ||
from querent.collectors.fs.fs_collector import FSCollectorFactory | ||
from querent.common.types.querent_event import EventState, EventType | ||
from querent.config.collector.collector_config import FSCollectorConfig | ||
from querent.common.uri import Uri | ||
from querent.config.core.llm_config import LLM_Config | ||
from querent.ingestors.ingestor_manager import IngestorFactoryManager | ||
import uuid | ||
import numpy as np | ||
from querent.core.transformers.bert_ner_opensourcellm import BERTLLM | ||
from querent.querent.resource_manager import ResourceManager | ||
from querent.querent.querent import Querent | ||
from postgres_utility import DatabaseManager | ||
|
||
async def ingest_all_async(): | ||
db_manager = DatabaseManager( | ||
dbname="querent_test", | ||
user="querent", | ||
password="querent", | ||
host="localhost", | ||
port="5432" | ||
) | ||
|
||
db_manager.connect_db() | ||
db_manager.create_tables() | ||
directories = ["/home/nishantg/querent-main/querent/tests/data/readme_assets"] | ||
collectors = [ | ||
FSCollectorFactory().resolve( | ||
Uri("file://" + str(Path(directory).resolve())), | ||
FSCollectorConfig(config_source={ | ||
"id": str(uuid.uuid4()), | ||
"root_path": directory, | ||
"name": "Local-config", | ||
"config": {}, | ||
"backend": "localfile", | ||
"uri": "file://", | ||
}), | ||
) | ||
for directory in directories | ||
] | ||
|
||
result_queue = asyncio.Queue() | ||
|
||
ingestor_factory_manager = IngestorFactoryManager( | ||
collectors=collectors, result_queue=result_queue | ||
) | ||
ingest_task = asyncio.create_task(ingestor_factory_manager.ingest_all_async()) | ||
resource_manager = ResourceManager() | ||
bert_llm_config = LLM_Config( | ||
# ner_model_name="English", | ||
rel_model_type = "bert", | ||
rel_model_path = 'bert-base-uncased', | ||
fixed_entities = [ | ||
"university", "greenwood", "liam zheng", "department", "Metroville", | ||
"Emily Stanton", "Coach", "health", "training", "athletes" | ||
], | ||
sample_entities = [ | ||
"organization", "organization", "person", "department", "city", | ||
"person", "person", "method", "method", "person" | ||
], | ||
is_confined_search = True | ||
) | ||
llm_instance = BERTLLM(result_queue, bert_llm_config) | ||
|
||
class StateChangeCallback(EventCallbackInterface): | ||
def handle_event(self, event_type: EventType, event_state: EventState): | ||
if event_state['event_type'] == EventType.Graph: | ||
triple = json.loads(event_state['payload']) | ||
db_manager.insert_metadata( | ||
event_id=triple['event_id'], | ||
subject=triple['subject'], | ||
subject_type=triple['subject_type'], | ||
predicate=triple['predicate'], | ||
object=triple['object'], | ||
object_type=triple['object_type'], | ||
sentence=triple['sentence'], | ||
file=event_state['file'], | ||
doc_source=event_state['doc_source'], | ||
score=triple['score'] | ||
) | ||
elif event_state['event_type'] == EventType.Vector: | ||
triple_v = json.loads(event_state['payload']) | ||
db_manager.insert_embedding( | ||
event_id=triple_v['event_id'], | ||
embeddings=triple_v['embeddings'], | ||
) | ||
|
||
llm_instance.subscribe(EventType.Graph, StateChangeCallback()) | ||
llm_instance.subscribe(EventType.Vector, StateChangeCallback()) | ||
querent = Querent( | ||
[llm_instance], | ||
resource_manager=resource_manager, | ||
) | ||
querent_task = asyncio.create_task(querent.start()) | ||
await asyncio.gather(ingest_task, querent_task) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(ingest_all_async()) |
Oops, something went wrong.