neuroqrs package#

Submodules#

neuroqrs.genai module#

class neuroqrs.genai.SuggestedQueries(*, suggestions: List[str])[source]#

Bases: BaseModel

Suggested Queries model

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'suggestions': FieldInfo(annotation=List[str], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

suggestions: List[str]#
async neuroqrs.genai.get_genai_suggestions(partial_query: str, context: dict, fields_info: dict, n_queries: int = 10) SuggestedQueries[source]#

Get genai suggestions for the given partial query, context and fields_info, Uses latest function call architecture.

Parameters:
  • partial_query (str :type context: dict) – The partial query for which suggestions are needed

  • context – The context for the query

  • fields_info (dict) – The fields information

  • n_queries (int, optional) – Number of queries to suggest, defaults to 10

Returns:

Suggested queries

Return type:

SuggestedQueries

neuroqrs.index module#

class neuroqrs.index.NeuroIndex(namespace: str = '', dim: int = 768)[source]#

Bases: object

Faiss powered index for searching through the dataset

add(document_text: str, embedded_document_text)[source]#

Add a document to the index and save the query

Parameters:
  • document_text (str) – Document text

  • embedded_document_text (list) – Embedded document text

static from_namespace(namespace: str, dim: int = 768)[source]#

Create a new index from existing namespace

save()[source]#

Save the index to the namespace

search(embedded_query: list, k: int = 5, return_scores: bool = False)[source]#

Search the index for the given query

Parameters:
  • embedded_query (list) – Embedded query

  • k (int) – Number of results to return

  • return_scores (bool) – Return scores or not

Returns:

List of results

Return type:

list

neuroqrs.main module#

class neuroqrs.main.NeuroQRS(embedding_model='all-mpnet-base-v2', model_dim: int = 768)[source]#

Bases: object

NeuroQRS main class

async query_and_index(query: str, namespace: str, extra_documents_data: dict, fields_info: dict = {}, k: int = 5)[source]#

Query and index the document (slow, uses even genai to improve context)

Parameters:
  • query (str) – partial query to search

  • namespace (str) – Namespace associated

  • extra_documents_data (dict) – extra supporting data, simply dumped to llm prompt

  • fields_info (dict) – fields information (ie what filters are avaliable for the search)

  • k (int) – Number of results to return

Returns:

List of results

Return type:

list

async query_maybe_index(query: str, namespace: str, extra_documents_data: dict, fields_info: dict = {}, k: int = 5)[source]#

Query the document quickly for results, if not enough results then index the document and query again (might be slow)

Parameters:
  • query (str) – partial query to search

  • namespace (str) – Namespace associated

  • extra_documents_data (dict) – extra supporting data, simply dumped to llm prompt

  • fields_info (dict) – fields information (ie what filters are avaliable for the search)

  • k (int) – Number of results to return

Returns:

List of results

Return type:

list

async quick_query(query: str | array, namespace: str, k: int = 5)[source]#

Quickly query the index

Parameters:
  • query (str) – partial query to search or embedded query

  • namespace – Namespace associated

  • k (int) – Number of results to return

Returns:

List of results

Return type:

list

neuroqrs.utils module#

neuroqrs.utils.add_doc_to_index(index: IndexFlatIP, embedded_document_text)[source]#

Add doc to index

neuroqrs.utils.create_empty_faiss_index(dim)[source]#

Create a new index

neuroqrs.utils.get_faiss_index(loc)[source]#

Get the index

neuroqrs.utils.get_text_queries(loc)[source]#

Get the text queries

neuroqrs.utils.save_index(index, loc)[source]#

Save the index and dataset pickle file to local

neuroqrs.utils.save_text_queries(queries, loc)[source]#

Save the text queries

neuroqrs.utils.search_index(embedded_query, index: IndexFlatIP, doc_map, k=5, minimum_score_threshold=0.7, return_scores=False)[source]#

Search through the index

Module contents#