From 0ccf7e17129f80b9a4d86ba39c0c6af1644ffdb6 Mon Sep 17 00:00:00 2001 From: shiyu22 Date: Tue, 27 Jun 2023 15:29:33 +0800 Subject: [PATCH] Update QA chatbot Signed-off-by: shiyu22 --- .../nlp/question_answering_system/README.md | 68 +++++------- .../server/Dockerfile | 15 +-- .../server/requirements.txt | 8 +- .../server/src/QA_data/example_data.csv | 100 ------------------ .../server/src/__init__.py | 0 .../server/src/config.py | 11 +- .../server/src/encode.py | 43 ++++---- .../server/src/main.py | 26 ++--- .../server/src/milvus_helpers.py | 71 ++++++------- .../server/src/operations/__init__.py | 0 .../server/src/operations/count.py | 5 +- .../server/src/operations/drop.py | 7 +- .../server/src/operations/load.py | 18 ++-- .../server/src/operations/search.py | 8 +- 14 files changed, 121 insertions(+), 259 deletions(-) delete mode 100644 solutions/nlp/question_answering_system/server/src/QA_data/example_data.csv create mode 100644 solutions/nlp/question_answering_system/server/src/__init__.py create mode 100644 solutions/nlp/question_answering_system/server/src/operations/__init__.py diff --git a/solutions/nlp/question_answering_system/README.md b/solutions/nlp/question_answering_system/README.md index c55fbd7d6..c73df2dcf 100644 --- a/solutions/nlp/question_answering_system/README.md +++ b/solutions/nlp/question_answering_system/README.md @@ -1,15 +1,12 @@ -# Quick Start +# QA System Based on Milvus & Towhee +This project combines [Milvus](https://milvus.io/) and [Towhee](https://towhee.io/) to build a question and answer system. This aims to provide a solution to achieve semantic similarity matching with Milvus combined with AI models. -This project combines Milvus and BERT to build a question and answer system. This aims to provide a solution to achieve semantic similarity matching with Milvus combined with AI models. - -> This project is based on Milvus2.0.0-rc5 +More example about LLM(ChatGPT etc.) for chatbot, you can refer to the [**Enhanced QA**](https://towhee.io/tasks/detail/pipeline/retrieval-augmented-generation). ## Data description -The dataset needed for this system is a CSV format file which needs to contain a column of questions and a column of answers. - -There is a sample data in the data directory. +The dataset for this system is a CSV format file which needs to contain a column of questions and a column of answers. And there is a sample data in the [data](./data) directory. ## How to deploy the system @@ -17,13 +14,14 @@ There is a sample data in the data directory. The system will use Milvus to store and search the feature vector data, and Mysql is used to store the correspondence between the ids returned by Milvus and the questions data set, then you need to start Milvus and Mysql first. -- **Start Milvus v2.0** +- **Start Milvus v2.2.10** - First, you are supposed to refer to the Install [Milvus v2.0](https://milvus.io/docs/v2.0.0/install_standalone-docker.md) for how to run Milvus docker. +First, you are supposed to refer to the Install [Milvus v2.2.10](https://milvus.io/docs/install_standalone-docker.md) for how to run Milvus docker. - > Note: - > - > Please pay attention to the version of Milvus when installing +```bash +$ wget https://github.com/milvus-io/milvus/releases/download/v2.2.10/milvus-standalone-docker-compose.yml -O docker-compose.yml +$ sudo docker-compose up -d +``` - **Start MySQL** @@ -48,23 +46,24 @@ The next step is to start the system server. It provides HTTP backend services, | **MYSQL_HOST** | The IP address of MySQL. | 127.0.0.1 | | **MYSQL_PORT** | The port of MySQL | 3306 | - ``` - $ export Milvus_HOST='127.0.0.1' - $ export Milvus_PORT='19530' - $ export Mysql_HOST='127.0.0.1' + Please use **your IP address** to instead of '127.0.0.1'. + ```bash + $ export MILVUS_HOST='' + $ export MILVUS_PORT='19530' + $ export MYSQL_HOST='' ``` - **Run Docker** > This image qa-chatbot-server:v1 is based Milvus2.0-rc3, if you want to use docker to start the Q&A server with Milvus2.0-rc5, please use the Dockerfile to build a new qa-chatbot image. - ``` + ```bash $ docker run -d \ -p 8000:8000 \ - -e "MILVUS_HOST=${Milvus_HOST}" \ - -e "MILVUS_PORT=${Milvus_PORT}" \ - -e "MYSQL_HOST=${Mysql_HOST}" \ - milvusbootcamp/qa-chatbot-server:v1 + -e "MILVUS_HOST=${MILVUS_HOST}" \ + -e "MILVUS_PORT=${MILVUS_PORT}" \ + -e "MYSQL_HOST=${MYSQL_HOST}" \ + milvusbootcamp/qa-chatbot-server:2.2.10 ``` #### 2.2 Run source code @@ -72,23 +71,15 @@ The next step is to start the system server. It provides HTTP backend services, - **Install the Python packages** ```shell - $ cd server + $ git clone https://github.com/milvus-io/bootcamp.git + $ cd bootcamp/solutions/nlp/question_answering_system/server $ pip install -r requirements.txt ``` -- **wget the model** - - ```bash - $ mkdir -p server/src/models - $ cd server/src/models - $ wget https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/paraphrase-mpnet-base-v2.zip - $ unzip paraphrase-mpnet-base-v2.zip -d paraphrase-mpnet-base-v2/ - ``` - - **Set configuration** ```bash - $ vim server/src/config.py + $ vim src/config.py ``` Please modify the parameters according to your own environment. Here listing some parameters that need to be set, for more information please refer to [config.py](./server/src/config.py). @@ -97,19 +88,18 @@ The next step is to start the system server. It provides HTTP backend services, | ---------------- | ----------------------------------------------------- | ------------------- | | MILVUS_HOST | The IP address of Milvus, you can get it by ifconfig. | 127.0.0.1 | | MILVUS_PORT | Port of Milvus. | 19530 | - | VECTOR_DIMENSION | Dimension of the vectors. | 768 | + | VECTOR_DIMENSION | Dimension of the vectors. | 384 | | MYSQL_HOST | The IP address of Mysql. | 127.0.0.1 | | MYSQL_PORT | Port of Milvus. | 3306 | - | DEFAULT_TABLE | The milvus and mysql default collection name. | milvus_qa_search_1 | - | MODEL_PATH | The path of the model `paraphrase-mpnet-base-v2` | | + | DEFAULT_TABLE | The milvus and mysql default collection name. | qa_search | + - **Run the code** Then start the server with Fastapi. ```bash -$ cd server/src -$ python main.py +$ python src/main.py ``` #### 2.3 API docs @@ -151,12 +141,12 @@ After starting the service, Please visit `127.0.0.1:8000/docs` in your browser $ export API_URL='http://127.0.0.1:8000' $ docker run -d -p 80:80 \ -e API_URL=${API_URL} \ - milvusbootcamp/qa-chatbot-client:v1 + milvusbootcamp/qa-chatbot-client:2.2.10 ``` - **How to use** - Enter `WEBCLIENT_IP:80` in the browser to open the interface for reverse image search. + Enter `127.0.0.1:80` in the browser to open the interface for reverse image search. > `WEBCLIENT_IP` specifies the IP address that runs qa-chatbot-client docker. diff --git a/solutions/nlp/question_answering_system/server/Dockerfile b/solutions/nlp/question_answering_system/server/Dockerfile index 233c4a393..04f8fe24b 100644 --- a/solutions/nlp/question_answering_system/server/Dockerfile +++ b/solutions/nlp/question_answering_system/server/Dockerfile @@ -1,16 +1,11 @@ -From ubuntu:latest +FROM python:3.7-slim-buster + +RUN pip3 install --upgrade pip WORKDIR /app/src COPY . /app -RUN apt-get update && apt-get install python3-pip python3 -y && apt-get install wget -y && apt-get install zip -y - -RUN mkdir -p /app/src/models - -RUN wget https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/paraphrase-mpnet-base-v2.zip - -RUN unzip paraphrase-mpnet-base-v2.zip -d /app/src/models/paraphrase-mpnet-base-v2/ - -RUN pip3 install -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com +RUN pip3 install -r /app/requirements.txt +RUN python3 encode.py CMD python3 main.py diff --git a/solutions/nlp/question_answering_system/server/requirements.txt b/solutions/nlp/question_answering_system/server/requirements.txt index 430ba3827..15c562a5f 100644 --- a/solutions/nlp/question_answering_system/server/requirements.txt +++ b/solutions/nlp/question_answering_system/server/requirements.txt @@ -1,9 +1,9 @@ -PyMySQL +PyMySQL==1.0.2 uvicorn numpy -pymilvus==2.0.1 +pymilvus==2.2.11 +towhee==1.1.0 +towhee.models==1.1.0 fastapi python-multipart pandas -sentence_transformers==1.2.0 -gdown diff --git a/solutions/nlp/question_answering_system/server/src/QA_data/example_data.csv b/solutions/nlp/question_answering_system/server/src/QA_data/example_data.csv deleted file mode 100644 index 8458c90e4..000000000 --- a/solutions/nlp/question_answering_system/server/src/QA_data/example_data.csv +++ /dev/null @@ -1,100 +0,0 @@ -question,answer -Is Disability Insurance Required By Law?," Not generally. There are five states that require most all employers carry short term disability insurance on their employees. These states are: California, Hawaii, New Jersey, New York, and Rhode Island. Besides this mandatory short term disability law, there is no other legislative imperative for someone to purchase or be covered by disability insurance." -Can Creditors Take Life Insurance After Death?," If the person who passed away was the one with the debt, creditors generally cannot take the life insurance proceeds left as long as the beneficiary was a person. The money then belongs to that beneficiary, and as long as creditors do not have a claim against the beneficiary, they cannot take life insurance proceeds from them." -Does Travelers Insurance Have Renters Insurance?," One of the insurance carriers I represent is Travelers and yes, you can purchase Renters insurance through Travelers. I would look for a local agent who can assist you in placing a renters policy if you are interested. I am sure the local agent would be happy to quote Travelers if they have access and other carries as well." -Can I Drive A New Car Home Without Insurance?," Most auto dealers will not let you drive the car off of the lot unless you have proof of insurance if there is a loan on the car. It is never a good idea to drive a car without insurance. If you traded a car in, then the coverage on the older car may extend to the new car temporarily, but you need to call your agent as soon as possible and get it changed. Most dealerships have an insurance agent they work with who can get you coverage as well." -Is The Cash Surrender Value Of Life Insurance Taxable?," Cash surrender value comes only with Whole Life Insurance, never with Term. It is the amount you can terminate your policy and receive. That amount includes both what you put in and what profit you made. The profit is taxable, just as most profit would be taxable. A far better idea would be NOT to surrender your Whole Life Policy, but instead to keep it and borrow against it and either then not repay it or choose to repay it as you wish. You continue to grow in value, even when the loan is out, and your policy stays in force, although the death benefit is reduced by the loan until it is paid back. There are numerous option you should discuss with a qualified agent. Gary Lane, Registered Representative, New York Life, 949 797 2424. Call anytime. Thank you." -How Is Annuity Income Reported?," The good news is that annuity income is usually reported by the insurance company issuing the annuity. When they make a disbursement they also issue appropriate documentation to assist in filing your taxes. They send identical information to the Internal Revenue Service. Generally speaking when money is withdrawn from an annuity it is treated as interest and then taxed as ordinary income until the interest is exhausted and only the basis (the sum of premiums paid) remains. That money can be recovered free of income tax. If the annuity is annuitized, that is paid out in monthly installments either over an extended period of time or the lifetime of the annuitant, then an exclusion factor is determined and applied to each payment. A part of each payment will be taxed as ordinary income. The bad news is that these principles apply to non-qualified annuities held by individuals and these barely touch all the situations that can arise and the taxation of those unique situations. While this response is not meant to take the place of legal and accounting professional advice it should alert you to some of the complexities of taxing annuities. The most obvious situation is when an annuity is held as an asset of qualified pension plan. This includes defined benefit plans. defined contribution plans (401(k), IRAs and many others. The income taken by these plans is taxed as ordinary income unless it is taken prior to age fifty-nine and a half. If taken earlier it could be subject to a penalty tax of an additional ten per cent. Where annuities taxation becomes complex is when deferred annuities are transferred. That is when a person gives another person an annuity on their life, or the life of a third party. The basic rule is that the transfer is treated as surrender and taxed accordingly. The annuity that is transferred is treated as having been fully paid. It then has a basis of the value that was taxed. For estate planning reasons the ownership of an annuity is sometimes held by a trust and this leads to another set of taxation considerations involving the non-natural person rule. Who is going to be taxed is the basic issue and this can be quite tangled. Of course there are exceptions to all of these rules. Taxation is fairly straightforward if the annuity is annuitized. State laws concerning probate can create some unexpected outcomes and taxation. When an individual owns an annuity and the annuitant is another person, perhaps a spouse, the death of the owner triggers the beneficiary provision and another third person could suddenly own the contract upsetting the intentions of the couple, even if it is a child. Many of the taxation rules are specific to individual insurance companies and it is wise to carefully make sure that the company you select from whom to purchase the annuity follows the procedures that will maintain your plan and keep taxation as uncomplicated as possible. Absent all other plans, the IRS frequently calls for a liquidation of a transferred annuity within five years. The key is the desire to get the tax question settled." -What Does AAA Home Insurance Cover?," AAA Home insurance, like all other major carriers, covers a wide variety of claims, including fire, theft, vandalism, and many other items. However, there are numerous types of policies offered, so it is best to determine the type of policy you have to accurately understand all of the benefits. An experienced broker can help." -What Is A Simple Retirement Plan?," what is a SIMPLE retirement plan? A Simple is an inexpensive opportunity for a small business to have a retirement plan that doesn't break the bank in advisor fees. A Simple plan is an IRS approved plan with only a few steps to follow so expensive testing and record keeping aren't necessary. For any small business who are considering a retirement plan to offer, this should be right on top as it does provide a great platform for a business who would rather use it's money to put towards employees retirements rather than third party administers plans." -What Does Social Security Disability Insurance Cover?, Social Security Disability Insurance pays a monthly benefit to people who cannot work due to a disability. The benefit is paid in cash to the recipient to use as they wish. it is not paid to an institution or entity. An injury or illness that causes the person to be unable to work is covered. -Is Car Insurance Prepaid?," Yes, automobile insurance is typically paid in advance. Normally no less than thirty days at a time. Each carrier sets their own requirements as to the initial payment amount for new coverage. Most carriers allow clients to pay monthly, quarterly, semi-annually, or annually. If you pay your premium in full for semi-annual or annual you may also receive a discount on your rate ( this is solely at the discretion of the carrier )." -What Does Medicare Part B Cover?," Medicare Part B covers the doctor services, outpatient hospital services, medical services and supplies. There is a monthly cost charged to the Social Security check received. There is a deductible and 20% copayments if incurred. In addition you pay all costs for services and supplies not covered by Medicare." -Can Veterans Get Life Insurance?," Unless a service person gets Veterans Group Life Insurance (VGLI) within a year from separating from the service, their Servicemembers Group Life Insurance (SGLI) will end and they will need to get a private policy. Contact an agency or website that carries several products to choose from to find the best rate for Veteran's life insurance." -Does My Homeowners Insurance Cover Lost Wedding Ring?," Great question. Generally no, your Homeowners' policy will not cover for anything that is lost. This is referred to as Mysterious Disappearance in your policy documents and is usually listed as a specific exclusion. That having been said, you can certainly obtain coverage for such a loss by working with your insurance professional and asking that the item be insured specifically either as a rider which is attached to your Homeowners' policy or as a stand alone separate policy. You will need to provide a current appraisal and the item would be insured to the stated amount on the appraisal. Such riders or separate policies (commonly referred to as Personal Inland Marine) include much broader coverage than does a standard Homeowners policy and will cover for such a loss." -How Does Assigned Risk Auto Insurance Work?, Assigned risk in California which is what I amfamiliarwith is a processing center by which people having trouble buying auto insurance are connected with an insurance company that will insure them. Assigned Risk is not an insurance company but are companies that are required by law to participate. The amount of autos an insurance company has on the road would constitute the percentage of their obligation to the plan. There is financial hardship criteria to qualify for Assigned Risk. Also agents who offer Assigned Risk must becertifiedto offer this coverage. You can go online and then beconnectedto an agent to see if you qualify for assigned risk. -Can My Boyfriend Add Me To His Car Insurance?, If you are living in the same household then he should put you on the list of drivers. The insurance follows the car and that is linked to a household. The person buying the insurance is in the household and can loan the car to whoever he wishes. The insurance covers the automobile. If you are not living together there wouldnt be anything gained by putting you on the policy. -Do I Need A Police Report To Submit A Claim For A Car Accident On Private Property?," Actually, though the local police might prepare an accident report for you, in many cases, because the incident occured on private property, it is more likely that they would take no action at all. Therefore, if it is possible, it becomes more important to exchange information with the other party involved. I would also recommend that neither car be moved and that you take photos for your records and that of your Insurance Company to help in the processing of the claim." -Does Full Coverage Auto Insurance Cover Repairs?," By Full Coverage I am assuming you mean, does carrying Comprehensive and Collision coverage cover repairs? If you have a covered claim i.e. -an accident, hit a deer, backed into your wife's car like I did the other week - then yes, carrying Comprehensive and Collision coverage would pay to fix those covered damages subject to your poilcy deductible. If you are experiencing general vehicle issues, i.e. - motor running roof, transmission mission or other general wear and tear - no, your insurance coverage would not come into play in these cases. Insurance only comes into play to repair a vehilce when there is a covered claim." -Is Life Insurance Acceptable In Islam?," Do to its use of interest and chance there are those who believe that insurance is not permitted in Islam (i.e. that it is haram or sinful). Due to the spiritual nature of this question, you should seek the advice of an Imam for further guidance on Islam's position on insurance." -Will Health Insurance Cover A Tubal Reversal?," Most insurance plans will not cover the reversal of a voluntary sterilization or any treatments designed to overcome infertility. There are fifteen states with insurance mandates requiring some form of coverage for infertility, but every one of these mandates specifically excludes covering reversal surgeries. The best alternative is to take advantage of the tax deductible expenses, and to buy extra coverage for any resulting pregnancy: lower deductible health insurance, short term disability, hospital indemnity." -How Much Life Insurance Can You Get If You Have Been Diagnosed With Breast Cancer?," Traditionally, you can get up to 20-30x your income level of life insurance. The medical history does not necessarily limit how much you can get. The medical history determines the risk classification which controls the premiums for the coverage you want to put in place. When it comes to breast cancer, the details of the medical condition will determine which carriers will offer coverage and what the risk classification would be (each carrier has different underwriting, you may not get the same risk class offer from each of them), The best thing to do is to shop the case via an independent insurance agent/broker who can shop it to multiple companies. You do NOT want to apply to multiple companies as this can work against you due to the MIB (Medical Information Bureau) - from a company's point of view, it's sort of like a red flag if you will if they saw you applied to multiple companies which they can check the MIB for. In order to secure the most accurate quotes for the coverage, a number of factors would need to be known such as when the cancer was diagnosed, what stage is it in/was it in, how was it treated, has treatment been completed, are there anymore tests scheduled or that need to be completed, are you being treated for any other conditions, what prescriptions do you take, family medical history, and other factors. If you have a copy of the pathology report, that will help with a lot of the input. If cancer is current, guaranteed-issue whole life (GIWL) will be the only type of coverage available as it doesn't have any medical questions or exam requirements. However, the amount of coverage available under a single policy is $20,000-$25,000, depending on the carrier. To get more than that, you would need to stack multiple policies. Under GIWL policies, they traditionally feature a 2 or 3 year graded period - meaning you only have accidental death coverage during those periods, otherwise the carrier just returns the premiums paid into the policy if death occurs during the graded period. After the graded period expires, the full benefit is payable. Carriers typically only issue fully-underwritten coverage if the cancer has been in remission/treatment completed for at least 2 years. Many carriers prefer 5+ years from the date treatment was completed for a more favorable risk class. Send me a message via the contact me button by my profile picture if you would like me to assist with your coverage. My group is licensed with about 50 different carriers in numerous states. I hope the information is helpful - please let me know how I can be of further assistance. Thanks very much." -What Do I Need To Register For Medicare?, If you have paid taxes into the system then enrollment is automatic. You should receive your Medicare card and a packet of information from Medicare shortly before you turn 65 or qualify for Medicare if you are on disability. If you do not receive your card by the time you turn 65 then you need to call your Social Security office or 1-800-MEDICARE. -Does Short Term Disability Insurance Work?," Short-term Disability does work if you have a qualifying disability. When you are applying for short or long-term disability, you need to look at the definition of disability and occupation. Not all companies have the same definition. If the definition is vague, you may find yourself being denied on your claim or receiving a lesser amount then what you have applied for." -Will Homeowners Insurance Cover Pool?," In short, the answer is yes. But it needs to be clarified whether you are asking for property damage to the pool itself or liability coverage. Both would be covered barring any specific pool exclusions, which I am not aware of any in the standard market. If someone were to get injured while swimming in the pool, yes, your homeowners policy should cover you for liability. Likewise, if you pool is damaged due to the standard homeowners causes of loss less any standard exclusions then the pool would be covered for property damage to the pool itself. Keep in mind that wear and tear would not be covered under your policy. So if your pool liner rips just because or the concrete foundation cracks, those would be considered wear and tear. Please note that many insurance carriers are very cautious when writing homeowners insurance on homes that have pools. Some do not like to write them with a pool exposure, some do not mind, so be sure to ask your agent how it might affect your current coverage and future coverage and what the premium impact might be. You also want to strongly consider higher liability limits in purchasing an umbrella or if you already have an umbrella policy then higher umbrella limits. It might cost you $150 for each additional $1 mil limit. Lastly, if you have a pool and want to make sure you are covered for the proper limits, make sure your coverage B (other structures) limit is sufficient to cover any losses to your pool and any other structures i.e. detached garages, sheds as well." -When Do I Have To Sign Up For Medicare?," You should sign up for Medicare in the three months before the month of your 65th birthday, the month of your 65th birthday, or in the three months following the month of your 65th birthday. If you miss that enrollment period you can sign up between Jan 1 and March 31 each year." -Will An MIP Affect My Car Insurance?," That is a great question! If you are the minor in question with the possession charge, you better bet it will. If the minor was someone in your car with you, and not you, you might get lucky and the insurance company won't find out. Now the fact that you were allowing the breaking of the law, suggests that your decision making skills need some work, and that as a result, at some point yes, that will affect your policy, as you will most likely be filing some claims. Please consider this a serious wake up call. Too many teenagers die as a result of drunk driving, and you don't ( and neither does anyone else on the road with you) need to be another sad statistic. Seriously, stop. Thanks for asking." -Does Blue Cross Blue Shield Have Life Insurance?," Blue Cross / Blue Shield is the name of the network association for a number of health insurance companies (includes Anthem and CareFirst). Many health insurance companies do also offer life insurance programs, however, it's typically not the type of coverage they specialize in and the products may therefore not be as competitive as insurance companies who feature life insurance programs as the main type of insurance they offer. Insurance companies specializing in life insurance tend to have more aggressive underwriting and can offer lower rates because they want to secure that type of business more than others. Please let me know if I can be of further assistance. Thanks very much." -What Are The Advantages And Disadvantages To Long Term Care Insurance?," The advantages of coverage in your senior years can be significant based on the average senior couple spending $250,000 in medical costs during their retirement years. The disadvantage is the loss of economic opportunity to invest or save the premium dollars spent on long term care insurance if you never use it." -Will Medicare Pay For Life Alert?, Medicare covers items that are considered medically necessary. This includes diagnosis and treatment of medical conditions caused by accident or illness. Medicare will also cover some DME (durable medical equipment) if prescribed by a doctor as part of your treatment plan. Services such as Life Alert are not considered medically necessary. -Which Life Insurance Should I Buy?," Product suitability is always a consideration when considering product lines that have such diverse application. Life insurance is generally purchased for indemnification or inheritance planning, but can be used as supplemental retirement income. Term life insurance is an excellent for temporary coverage for temporary financial exposure to your beneficiaries. For permanent liabilities, many planners use guaranteed universal life insurance. For supplemental retirement income there are several crediting methods: for interest rate crediting you can use participating whole life or current assumption universal life. If you desire access to domestic and/or foreign indices, you should review indexed universal life insurance. If your risk tolerance permits, you could consider variable universal life with access to separate sub accounts that use marker equities and bond instruments." -Does Medicare Pay For HPV Screening?," Medicare covers your annual exams including most women's gynocological exams and testing. As part of your pelvic exam and pap test, your doctor should screen for abnormalities including STD's, abnormal cells and HPV. The HPV virus has been linked to certain types of cervical cancer. You should have regular HPV screening and it is normally covered by Medicare" -Which Is The Best Life Insurance To Get?," The best life insurance to get is going to depend on many factors. The most prominent one being why are you taking out the policy. Otherwise, I would say a whole life policy is the one that will provide a lot of bang for the buck in most cases. To ensure that you get the policy that is right for you contact your local agent and discuss your needs and expectations so that they can direct you to the policy that best fits." -How Much Should Long Term Care Insurance Cost?," Long term care insurance premiums will vary greatly according to age, health, features of the policy, and area in which the policy is purchased. However, you could look at the federal guidelines for how much premium can be exempted on income tax returns, to get a general guide for life insurance premiums. In 2013, they are: 40 and under: $360/single, $720/couple 41-50: $680/single, $1,360/couple 51-60: $1,360/single, $2,720/couple 61-70: $3,640/single, $7,280/couple 71 and up: $4,550/single, $9,100/couple" -How Safe Are Fixed Annuities?," Tax deferred, fixed annuities are based on the contractual claims in the annuity policy. The contractual claims in the annuity policy are as good as the financial strength and claims paying of the annuity company that issued the policy. Generally, fixed interest rate annuities guarantee a rate for a period of time like 5, 7 or 10 years. The annuity insurance companys portfolio is generally dominated by government bonds." -How Long Does It Take To Settle A Life Insurance Claim?," Life insurance death claims are generally filed by the beneficiaries of the policy. The beneficiaries contact the insurance company for their death claim forms and return them with an obituary and certificate of death. The process should take between 30 and 60 days. If the death occurred within the two year contestability period, a standard investigation will ensue which can delay payment." -Is Car Insurance Credit Checked?, When you are applying for auto insurance coverage most if not all insurance carriers will do what is called a soft pull of an insured's credit score. This soft pull normally will not adversely affect a persons credit rating. Credit score is only one part of the many factors that are taken into consideration when your rate is calculated. -Can I Use HSA To Pay For Long Term Care Insurance?," Yes, you can use HSA to pay for long term care insurance premiums. There is a limit on the premiums for LTC insurance that can be paid through your health savings account. The instructions for your Section A (Form 1040) of your tax return will tell you the limit of premiums that can be deducted for your age group that year." -Can Employers Charge Smokers More For Health Insurance?," Yes. Application of a premium surcharge for tobacco users has become more common in recent years, primarily in larger groups who self-fund their employee benefits plans as the employer has much more control of the benefit plan design and rate structure than they do with fully insured plans. The Affordable Care Act (ACA), while doing away with pre-existing condition exclusions, does explicitly allow for the adjustment of rates for tobacco use. So, in that sense, tobacco users are the class of employees it is legal to discriminate or penalize for their personal behavior. The ACA is silent on the consumption of Marijuana which may present some interesting situations as more states move to allow the use of medical Marijuana or to legalize its recreational use." -What Does Home Owners Insurance Usually Cover?," That's kind of a tough question to answer becuase many homeowners policies cover a multitude of things. In general terms if you house catches on fire, is broken into, is damaged by wind hail or lightning, your pipes burst, some body trips and falls on your proprty and gets hurt you could have a claims situation on your homeowners policy. This is just scratching the surface as every policy is different in every state. Most carriers add in a bunch of extra coverages too. To truly know what your homeowners policy covers, you need to do two things 1) Call you local independent agent and discuss you policy with them 2) Actually read your policy. I know reading a legal contract is your idea of fun night curled up by the fire, but it is in your best interest to actually read your entire policy, know what it includes and excludes and ask your agent about things you have questions on...." -How Much Does An Ultrasound Cost Without Health Insurance?, Ultrasound exams are usually a few hundred dollars when you have health insurance. The Health Care Blue Book shows a price of $158 for an abdominal ultrasound including physician fees. Ultrasound on other body parts may be more or less. You should ask your doctor about costs in advance and negotiate an acceptable rate. -What Is 10 Yr Term Life Insurance?," That is a great question! A ten year term policy is one that provides you with the specified amount of coverage for the ten years as defined in your policy. On the day your policy expires, you have no more coverage, and no cash value or benefit to take from it. You can renew your policy, but it will dramatically increase in price. Typically a policy like this is to insure against a short term loss, like covering a college career, or a mortgage, or to provide a cheaper form of life insurance when money is tight. If you would like more details, please feel free to contact me, okay? Thanks for asking!" -Can You Put Money In A 401K And A Roth IRA?," That is an excellent question! Not only can you, but you should! It is an excellent strategy to maximize as much as you can afford to the amount you can contribute to your retirement funds. Contribute as much as you can to the 401 to earn the employer match, it's free money, in a way, and you should take advantage of it. Your Roth will allow $5500 a year ($6500 if you are 50+) and after your 401, contribute as much of that as possible. The earlier you start, the better, and by maximizing your contributions now, it will help balance out when the time comes that money is a little tighter, and you can't contribute as much. Thank you for asking!" -Can I Get Health Insurance With Hepatitis C?," You can purchase health insurance with Hepatitis C as a preexisting medical condition. There would be no waiting period before benefits begin, but time is quickly running out. The Affordable Care Act requires that health plans accept all applicants regardless of existing medical conditions. Applicants need to enroll in a plan during the annual open enrollment period through their state insurance exchange. The first open enrollment ends on March 31 of 2014 - in just a few days. Coverage would begin April 1. If you miss this open enrollment window you could enroll in plans with a January 1, 2015 effective date." -When Can I Enroll In Medicare Part A?," You will automatically be enrolled in Medicare when you reach age 65 provided you have worked long enough and paid into the system. You will have the choice to opt out of part B of Medicare, but I do not recommend it unless you are still working and in a group. You will also get Medicare if you are on Social Security Disability. There is about a two year wait when you get disability before you are eligible." -When Did Health Insurance Originate?," That is a great question! There were some types of travelers insurances offered in the 1840's that covered you if your train crashed or steamboat sank, but other than that, there really wasn't much until the late 1800's when disability policies became popular. Britain passed a law in the early 1900's that created a National Health Insurance, and most of Europe kind of adopted similar laws, but we didn't catch on until 1929 when us Texans ( Baylor University Hospital, and some local teachers, I think) created a system of standardized costs for hospital stays. Shortly thereafter came Blue Cross/Blue Shield, and then all kinds of competing companies. The history of insurance is interesting stuff. Thanks for asking!" -How Important Is Health Care Insurance?," Very important. Health insurance allows people to go and get health care if needed. Typically people with insurance will get check ups, find problems sooner due to early detection and can address health needs proactively. When you don't have health insurance you spend your days praying you never get sick. If at all possible strive to keep health insurance on yourself and your family." -How Much Does It Cost To Get Renters Insurance?," Great question. Often clients are afraid to ask I think they believe is it expensive but actually its relatively inexpensive. Typically if you insure two vehicles with a company the discount you gain by having a second policy on your auto insurance will if not cover the cost of a renters policy it will be close! So the average cost is 60-120 dollars a year. So for ten dollars or less you have coverage for your phone, computers, books, clothes, medications, cd's, movies, art, guns or whatever else you own! Ten dollars a month is very inexpensive, also these are covered anywhere in the world!" -Does My Home Insurance Cover Theft?," It is important to talk to your insurance professional about the specific terms and conditions of your policy, but generally speaking, theft is a named covered peril in most Home Insurance policies. This would include theft of your personal property from within your home of course, but also includes theft of your property outside of your home. Personal property outside of your home is usually covered up to 10% of the total personal property amount listed in your policy. If covered, the loss settlement would be subject to your deductible. The claims specialist will also be looking for a copy or a police report." -How Does Renters Insurance Benefit The Landlord?," That is a great question! The landlord needs to provide a safe environment for the tenants, and carries insurance on the property. To help protect the property manager/complex from a higher liability, your renters policy helps take some of that liability off of their shoulders. If you damage the apartment, or someone is injured in your apartment, your policy covers some or all of that claim, and not the landlords. Thanks for asking!" -Do Ohio Employers Have To Offer Health Insurance?," Employers in Ohio are required to offer health insurance to their workers although they can avoid any penalty if the family can not afford the healthcare benefits offered. Also, this penalty has been delayed until 2015 to give employers and insurers time to work on specific details of implementation. This tax penalty applies to companies with 50 or more workers and applies to workers and their dependents, including children under the age of 26. Technically, the law does not apply to spouses. Full-time would be considered working 30 hours per week. However, having 100 part-time workers working 20 hours per week would qualify as having 50 full-time workers. Here in Ohio, we have enjoyed low health insurance rates, and although required mandates will be raising premiums, there still will be many low-cost options.Most of the major insurers, including Anthem and Medical Mutual, will be participating in the State Health Exchange." -How Much Auto Insurance Should I Have?," I always recommend the highest limits of liability that you can afford. If you have a good insurance score, and a clean driving record, the premium difference between 50/100 (50k per person/100k per accident) and 100/300 will not be much relatively speaking. Also, it is a good idea to have a high limit of liability for property damage, such as $100,000. The national average vehicle liability award in 2008 was $326,628. That said, I always recommend at least 250/500 limits of liability. Additionally, I always recommend having an umbrella policy to increase your limits of liability. Ask your insurance agent for a quote on a $1,000,000 umbrella policy. Be sure to tell your agent of all properties or vehicles titled to you." -Why Does Homeowners Insurance Increase?," Homeowners Insurance is a contract whereby a homeowner transfers his/her risk to an insurance carrier in return for a contract and a small premium. Homeowners Insurance Premium will usually increase from year to year. however, by chance a decrease may be seen once in a while. Insurance companies increase the Dwelling Coverage each year to keep up with the increasing cost of reconstruction. after all, homeowners insurance's primary purpose is to rebuild a home in the unfortunate event of a total loss. The small increase of dwelling coverage each year is usually the purpose that draws attention when the premium rises. however, this is very insignificant. Insurance companies are audited each year and are obligated to comply with State Department of Insurance regulations in each and every State where they underwrite risk. Each year, insurance carriers calculate the necessary premium to maintain a safe financial condition and offer security to all homes insured. the largest reason for premium increase would be 'loss experience' during the prior year, another reason may be due to increased operational cost including but definitely not limited to reinsurance premium paid. Insurance Companies either have an internal actuarial department or hire an independent actuarial firm who are charged with the responsibility of calculating premium based on underwriting factors and prior loss data. For this reason, carriers only offer annual policies and are unable to predict risk on a longer term basis. Since carriers experience different loss results each and every year, insurance rates and increase percentages are never the same from one year to the next. Since paid losses continue to grow, claim frequency is showing growth and litigation is becoming more commonplace, insurance companies raise premium to keep up with the outflow of payments. It is important to recognize that claims and operational expenses are paid from the pool of collected policy premium. For a more detailed explanation or financial report from your current carrier, contact your carrier representative to receive a report. Also, data is available as published by the Department of Insurance in most States." -Who Can Buy Medicare?," That is a great question! The vast majority of people get Medicare when they are turning 65. The program will allow people under the age of 65 to enroll under certain conditions, like kidney failure, or if you have been on disability for a designated amount of time. The program is designed to help Senior Citizens afford health care, so unless you meet the exceptions, you will need to be 65 or older to enroll. Thanks for asking!" -How To Remove Medicare Part B?," --> Medicare makes it difficult to cancel, or withdraw from, Medicare Part B. Because Medicare Part B provides important coverage for most people 65 and older, and because there's a penalty if someone cancels Medicare but then later wants to enroll again, Medicare enrolls everyone automatically at age 65 and wants to make sure no one cancels their coverage without fully understanding the consequences." -At What Age Should I Get Long Term Care Insurance?," The best time to secure long term care insurance is when youre young and healthy, especially if you have a family history of chronic illness or nursing home confinement. Most advisers begin addressing long term care insurance with their clients and prospects around age 50. But in reality, most pre retirees purchase long term care insurance in their early 60s." -When Are Life Insurance Death Benefits Taxable?," Typically, life insurance proceeds are not taxable. They pass on to the beneficiary tax-free and can be deposited into a pre-approved or pre-discussed account. Based on my 32 years of experience handling too many claims, the period of time is about 10-30 days for the check to arrive. In some circumstances, there could be estate taxes. Also, depending on the type of policy and how premiums were paid, there could be a taxable event. A full-time broker or financial planner is your best resource." -What Are Medicare Savings Programs?," Medicare Savings Accounts (MSA) is a specific type of Medicare Advantage plan that may or may not be available in your area. Similar to the HSA (health savings account) for major medical plans, the MSA combines a high deductible Advantage plan with a tax favored savings account. These are not for everyone but there are definite advantages." -Does Homeowners Insurance Cover Dog Bites To Other Dogs?, Dog bites would be covered under the liability portion of your homeowners policy. Dog bites have become a big deal over the last several years and dog bite can be a very expensive loss in some cases. For this reason many insurance companies have put exclusions on certain breeds of dogs and will not cover a dog bite. You would need to check with your specific insurance company to see if your breed of dog is covered should a dog bit occur. All agents should be having this discussion with the client before purchasing a policy. -What Does Medicare Plan A Cover?, Medicare Supplement Plan A is required to be offered by all insurance companies who offer Medicare supplement plans. This plan covers 100% of the basic benefits that can be offered by insurance companies under a Medicare supplement plan and is suitable for individuals on a budget who want to have a little more coverage than what Medicare Part A and Part B provides. Medicare Supplement Plan A Covered Benefits: 1) Medicare Part A coinsurance plus coverage for 365 additional days after Medicare benefits are used up 2) Medicare Part B coinsurance or copayment 3) First 3 pints of blood 4) Part A hospice care coinsurance or copayment Benefits not covered: 1) Skilled Nursing Facility Care coinsurance 2) Medicare Part A deductible 3) Medicare Part B deductible 4) Medicare Part B excess charges 5) Foreign travel emergency (up to plan limits) Medicare supplement plans can be purchased through an insurance agent/broker. -Is Whole Life Insurance A Good Option?," The answer to any financial question should always be prefaced by it depends on the need of the individual. That said, there are significant benefits for someone who owns a whole life participating policy. Whole life, a form of permanent life insurance, features guaranteed premiums, death benefits and cash value. Whole life policies also give you the potential to receive dividends which can increase the value of the policy or provide an increased death benefit for beneficiaries. Unlike term, the death benefit will last your entire lifetime and the monthly premium will be locked in at the date of policy inception according to your rating. So, if you are 35 and get rated Preferred Non-tobacco that will give you a monthly premium that will not change for your entire life, regardless of any health issues - as long as your premiums are current. The second important value of whole life insurance is the accumulation of cash inside the policy on a tax-deferred basis. Over time, the cash value increases can be significant and you can borrow cash from your policy at a favorable interest rate. Many people have used this as a source for college funding or even a retirement income stream later in life. These policy loans are generally tax free. There is a lot more to Whole Life policies that can be addressed when considering your personal situation and I would recommend contacting an independent insurance agent that can review your particular needs and situation." -Can Employers Contribute Different Amounts Health Insurance?," They can as long as they are not discriminating within a class of employees. For example, it is not uncommon for an employer to contribute on dollar or percentage amount towards the coverage of salaried employees and another dollar or percentage amount towards hourly employees. This is quite common where a labor union collectively bargained agreement is in place. Where an employer can get in trouble is where they choose to discriminate within the same class of employees. So, as a general rule all salaried employees should be treated the same from an employer contribution standpoint as should be the case with all hourly employees. Contributing 50% of the cost for one salaried employee and 75% of the cost for another similarly situated salariedemployee could be the grounds for a labor discrimination lawsuit for the employer." -What Will Happen To Medicare In The Future?," Medicare is too big to fail but that does not mean there won't be changes. Funding and benefits will need to be adjusted in order for the system to survive. Medicare is like a balloon. You squeeze in one place and it bulges in another. Going forward, medical providers will have reimbursements squeezed, deductibles and premiums will rise. The biggest threat to Medicare beneficiaries is the Obamacare IPAB that will oversee medical treatment." -Can The General Life Insurance?, I was not able to find a General Life Insurance Company. I did find General American Life Insurance which has been bought by Metlife Insurance. Metlife is a good strong company to work with. I would however recommend comparing rates for the type of insurance you are looking for as they will have different features. -Will My Auto Insurance Go Up If Get Ticket?, That will depend primarily on your insurance carrier andyour previous motor vehicle record. Each carrier has its own policies on how tickets and accidents are used in their auto insurance rating system. Somecarriers will not change your rates due to a single ticket or accident within a five year time period. -Does Renters Insurance Include Theft?," If you're insured with a reputable company and a good agent, your renters policy should include theft. All a renters policy is is a homeowners policy without the building coverage. It's there to cover your stuff and your liability. It's rare, but there are companies that offer coverage that may not include theft. This coverage form is called Basic Form and it will not cover theft. Never, never, never accept a policy written on a basic form for your renters coverage. The most common form is Broad Form, and it will cover theft. Most companies and agents will use this when writing your renters policy. Don't accept anything less." -What Is A Renters Insurance Policy?," A renter's insurance policy covers your personal property when you do not own the residence you occupy. It also covers your liability, medical payments to others, additional living expenses and numerous other items. Typically, the cost is fairly cheap and an experienced broker in your area can easily compare the best plans for you." -How Is Home Insurance Calculated?," Among the many factors typically used to determine homeowner insurance rates, here are a few of the key ones: Type of Construction, Age of Dwelling & Condition of Dwelling - Ex: Is the construction type 'fire resistant' rather than wood frame? Has the building been well cared-for? Claims Submission History - Ex: Does the prospect have a history of submitting claims on a frequent basis...especially smaller ones? Dwelling Location - Fire station proximity. History of frequent and /or severe losses in the area from wild fires, hurricanes, etc. Credit History - Credit score - Prevailing underwriting theory is that better credit scores equate to less possibility of frequent claim submissions. Additional Risk Factors - Swimming pools, with or without child safety devices. Questionable types of animals in terms of temperment, as relates to possible attacks on humans. Recreation equipment on premises - safety devices?" -Does Homeowners Insurance Cover Sewer Repair?," No, under normal circumstances sewer repair would not be covered by your homeowners insurance policy. Remember every policy is different. Please read your policy completely to understand the coverage provided and any exclusions that there may be or contact your local agent to have them go over the policy with you." -Does AARP Have Long Term Care Insurance?," No, AARP does not carry Long Term Care insurance at this time. The American Association of Retired Persons does give tips to members on what to look for in long term care coverage and is committed to watching out for its age 50+ members in this area. To obtain Long Term Care quotes there are many online agencies that can assist you." -Is Short Term Disability Considered Health Insurance?," No short term disability is a different policy than health insurance. Health insurance is designed to pay the providers, i.e. doctors, hospitals, clinics, etc. Short term disability is designed to pay you for the income that is lost due to an injury or illness. It can be used for medical expenses, food, mortgage or anything else needed to survive during a difficult time." -At What Age Should You Get Life Insurance?," Most people I talk to wish that they had bought their life insurance a few years ago. One man recently was kicking himself around the block for not doing so. Obviously, the older you are the closer the company is to the day that they will have to pay a death benefit. In other words, as you age you become a greater risk to the company and the company must charge more to compensate." -Is Travelers Home Insurance Any Good?, In my personal opinion Travelers home insurance is a superior product. Also Travelers has excellent customer service and claims handling. As an independent agent I work with many different companies and the one that rises to the top and receives praises from my clients continually is Travelers Insurance. Make sure to discuss the details with an agent as Travelers has several package options ranging from Silver to Platinum. -Who Can Get On Medicare?," You are eligible for Medicare by one of two ways. The most common entry into Medicare is when you turn 65. Most folks take advantage of Medicare eligibility at 65, but if you have good group insurance through your employer you can opt-out of Medicare until retirement without penalty. The other entry into Medicare is via qualifying for Social Security Disability prior to the age of 65." -Who Has The Best Rates For Renters Insurance?, This is impossible to answer with the limited information provided here. Rates for renters insurance can vary greatly from area to area and carrier to carrier.Eachcarriersets their own rates for each area that they do business in. Contact local agents in your area to find out about available of coverageand pricing for the carriers in your area. -Who Can Drive Your Car Under Your Insurance?," All listed divers on your policy can operate your vehicles (assuming they are on your policy). Also, if you give permission to another person to drive your vehicle, and they are licensed and in good standing, they should be covered (assuming at-fault state). If another person steals your vehicle, you are covered for the damages they cause, although the insurer will certainly attempt to recover funds from them." -Can Medicare Pay For Nursing Homes?," Medicare can pay for nursing home stays under certain conditions: 1) The nursing home stay must be within 30 days of a qualified hospital stay in the hospital of at least days. 2) There must be a prescribed medical need for daily skilled nursing or rehabilitative care. 3) The facility must be Medicare approved. 4) Medicare will only continue as long as the patient is showing improvement. 5) The first 20 days are totally covered. Days 21-100 charge a co-payment that was $144.50 per day in 2012. After 100 days, Medicare no longer pays any benefits for nursing home care." -What Happens If Car Insurance Lapses?," If your car insurance lapses....pay that bill! Often, you have time where the insurer will accept your premium payment (but possibly with a lapse incoverage). If your policy has lapsed for a longer period of time, obtaining a new policy quickly is important. You should contact an experienced broker or a very reputable website with the idea of getting coverage that day. After reviewing multiple quotes, you can apply and purchase a policy (online, if you wish)." -Is Garage Door Covered By Homeowners Insurance?, A garage door is part of the dwelling so this means the garage door is covered by the same perils of the policy as the rest of the home minus your deductible. If it's attached to the home is part of the home. If it falls free then it's personal property and not dwelling. -Where Do I Sign Up For Medicare?," You can sign up for Medicare online at medicare.gov. If you are nearing age 65, you can sign up in the three months before or after the month of your 65th birthday. If you would rather sign up by phone, you can call 1-800-MEDICARE (1-800-633-4227). Or you can go to your local Social Security Office to sign up for Medicare." -How To Get The Best Deal On Auto Insurance?," Auto insurance rates vary per state and per company because they all have their own underwriting guidelines and rules. However, if you want to make sure that you are getting the best rate you need to NEVER have a lapse in coverage, keep your credit score up, have zero tickets, zero accidents, and always carry $100,000/$300,000 or higher liability limits." -How Do You Apply For Medicare Part D In New Jersey?," To apply for Medicare Part D in New Jersey, a good website to go to is: WEBSITELINK . There you will find some Medicare Part D plans to enroll in and how to enroll in Medicare Part D plans in New Jersey. They also provide a phone number where you can contact them to enroll in Medicare Part D." -Which Company Offers The Best Renters Insurance?," To find the best renters insurance policy for you, I would suggest that you talk with your friends and family about their experiences and knowledge of the carriers in your area that handle renters insurance. Insurance policies are as unique as the people that purchase them. Your best bet is to find yourself a good local agent and they will help provide you with the information that you need to make an informed decision." -What Are Some Characteristics Of Whole Life Insurance?," Whole Life, also called Permanent Life, will last for the rest of your life, so long as you pay your premiums. Unlike Term Life, which lasts for a specific predetermined number of years, at a guaranteed rate. Whole life will not go up in price and will not go down in coverage amount. It accumulates cash value, from which you are able to borrow funds, for such things as college, home down payment, or even retirement, or whatever else you desire. With the accumulation in a quality policy, you can fund your retirement, as a substitute for a pension. Thank you. GARY LANE." -What Is Annuity Kind Of Cash Flow?," In finance, an annuity cash flows are any cash flow that you receive on a consistent basis during a certain period of time. The period of time can be time dependent (i.e. 20 years) or event dependent (the life of an individual)." -Can You Get Life Insurance After Breast Cancer?," Breast cancer has four stages. Depending on the stage, surgery performed and recovery management, i.e. regular checkups, etc. life insurance may be possible to obtain. Depending upon the history and current medical condition there are three possible avenues to explore based on what stage the cancer is in: fully underwritten, simplified issue or guaranteed issue." -How To Figure Out How Much Car Insurance Will Be?," You can figure out how much your car insurance will cost by going online and comparing quotes. You'll have to provide some basic information such as the type of car you drive, your age, zip code etc... Also, as experienced brokers, we can be contacted directly and we will shop the top-rated carriers for clients. Of course, if you have existing coverage, don't cancel a policy unless you are already approved for new coverage." -How To Plan For Retirement With A 401K?," A qualified, employer sponsored, defined contribution retirement plan like a 401(k) is one of the most popular savings options. Some employers offer an additional contribution match furtherenhancingyour pretax contributions. Many advisers recommend that baby boomers work until age 70 1/2 to contribute as much as possible due to the risk of longevity duringretirement and required minimum distributions are triggered for income." -What Is The Tax Penalty For Not Having Health Insurance Under Obamacare?," The first year penalty is only $95.00 and will gradually increase. In 2016 the penalty will be adjusted to the CPI or Consumer Price Index. Most people will qualify for a subsidy to pay the monthly premium. Those individuals between 133% & 400% of FPL or Federal Poverty Level. The amount varies by state, in NM for example, if an individual makes less than $45,900 Modified Adjusted Gross Income, & $92,000 for a couple filing jointly, they will qualify for a tax subsidy. The less you make the larger the subsidy. There is catastrophic coverage available for those under 27 years of age. Bronze which pays 60%, with a 40% member coinsurance, Silver 70/30, Gold 80/20, & Platinum 90/10. My company is licensed in several states, feel fee to contact me with additional questions. Or to get qualified through the Health Care Marketplace starting October 1st, 2013. Enrollment runs through December 31st, 2013. Coverage to begin January 1, 2014." -Can You Lose Medicare Benefits?," This is a great question. The only time I have seen someone's Medicare terminate is when they stopped paying the bill. Normally part A is at no cost and there is a cost for part B. For most, part B is taken directly from the social security check, but sometimes there is no social security check and Medicare sends a bill. So the short answer is Yes." -Will Homeowners Insurance Cover A Lost Diamond?," Homeowner's insurance can potentially pay for a lost diamond if you have it scheduled on your policy. When this is done, you are covering the ring for a specified amount, and generally all risks are covered. The premium charged is in addition to the regular policy premium. There also may be a rider that extends coverage to include that risk, althoughschedulingis often the best option." -How Much Do Long Term Care Insurance Policies Cost?," The cost of a typical long term care insurance policy depends on gender, age and health condition. Sometimes where you live can affect the cost as well. A typical male and female, each age 60 nonsmoker on a joint long term care policy with a good company will pay around $300 a month for long term care coverage." -When Should I Stop Paying For Life Insurance?," You should stop paying for life insurance when you have eliminated all your financial liabilities and future obligations, including charitable intent. You could also stop paying for life insurance if you have no beneficiaries, business partners or charities. You could stop paying for your cash value life insurance if the performance of the policy results in the policy sustaining itself to maturity. To be sure of the performance, or lack thereof, you need to order an in force ledger from the life insurance company." -What Age Do You Go On Medicare?," Most people go on Medicare at age 65. You cannot get on Medicare at a younger age unless you meet the guidelines for qualification while having Lou Gherig's Disease or End Stage Renal Disease, or if you have been receiving Social Security Disability benefits for at least two years." -How Can Life Insurance Companies Tell If You Are A Smoker?," Life insurance companies can tell if you are a smoker by testing blood and urine, by asking about tobacco use on the application, sometimes by doing a phone interview, and sometimes by looking at medical records. The insurance companies can't always tell, but it is surprising how many people get caught using tobacco when they think they won't. And once that trust is broken between what was stated and what is true, the underwriters don't give you much benefit of the doubt for anything else." -How To Determine If You Need Long Term Care Insurance?," Ask yourself these questions: Do you own your home? Do I want to pass it to my family? What about my other assets? If I had to go to a nursing home do I want to have to spend down my assets to qualify for Medicaid? What will my family do if this happens? Proper planning can help insure that when your time comes that you need care your family will not have to suffer the burden of taking care of your personal needs. Help will be available to allow you to stay at home rather than being forced into a nursing home and losing all your hard earned money and assets. Talk to a good Care Resource Planner familiar with not only Long Term Care Insurance, but also Medicaid, Veterans Benefits, and other sources that could save you literally thousands of dollars." -Who Made Car Insurance Mandatory?," If car insurance is mandatory, there are two possible entities that make it so - either your State Department of Motor Vehicles or your auto loan or leasing company. Usually these days it is both. Most states require car insurance as part of their procedure for registering a car. In all cases if you have a loan, the lender will require you to carry both Comprehensive and Collision coverage in order to be sure that their interest is protected. If you are leasing your car, not only will Comp and Collision be required, but Liability coverage as well." -When Should I Get Term Life Insurance?," The best time to get coverage is obviously the day before we die! Now, since most of us don't know when that is or will be, the best decision you can make is to get coverage if you have responsibilities to others. Whether it be for a loan repayment or college education and money for a spouse, make sure this is something you do NOT put off." -What Does Credit Have To Do With Auto Insurance?," Many insurers utilize credit scores when determining the auto insurance rate a customer will pay. The reason is that often, there is a direct correlation and relationship with bad credit and higher incidence of accidents. Although the discount or surcharge may not be large, it is till worthwhile to be aware of your current credit rating and take steps to monitor and improve it." -Will Home Insurance Pay For Roof Replacement?," It may if your roof was damaged by a covered incident less your policy deductible. Many homeowners policies have a different deductilbe for wind, hail, or roof claims. Please remember every policy is different. Read your policy completely to understand the coverage provided and any exclusions that there may be." -Who Has The Best And Cheapest Car Insurance?," This is a difficult question to answer because all companies are different in what makes up their ideal market. Some companies specialize in 30+ year olds, others in young drivers. Local has a lot to do with car insurance rates as well. In addition, insurance rates are based off the type of coverage an individual is seeking. So to say one company is the best and cheapest is really impossible to do. I would suggest contacting an agent in your state and provide them information specific to you. They should be able to narrow companies down that will suite your individual needs. Then compare coverage and rates to find the best company for you!" diff --git a/solutions/nlp/question_answering_system/server/src/__init__.py b/solutions/nlp/question_answering_system/server/src/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/nlp/question_answering_system/server/src/config.py b/solutions/nlp/question_answering_system/server/src/config.py index 3b0db1280..fafdc8c47 100644 --- a/solutions/nlp/question_answering_system/server/src/config.py +++ b/solutions/nlp/question_answering_system/server/src/config.py @@ -2,25 +2,22 @@ ############### Milvus Configuration ############### MILVUS_HOST = os.getenv("MILVUS_HOST", "127.0.0.1") -# MILVUS_HOST = os.getenv("MILVUS_HOST", "192.168.1.85") MILVUS_PORT = int(os.getenv("MILVUS_PORT", "19530")) -VECTOR_DIMENSION = int(os.getenv("VECTOR_DIMENSION", "768")) +VECTOR_DIMENSION = int(os.getenv("VECTOR_DIMENSION", "384")) INDEX_FILE_SIZE = int(os.getenv("INDEX_FILE_SIZE", "1024")) METRIC_TYPE = os.getenv("METRIC_TYPE", "IP") -DEFAULT_TABLE = os.getenv("DEFAULT_TABLE", "milvus_qa_search_1") +DEFAULT_TABLE = os.getenv("DEFAULT_TABLE", "qa_search") TOP_K = int(os.getenv("TOP_K", "10")) ############### MySQL Configuration ############### MYSQL_HOST = os.getenv("MYSQL_HOST", "127.0.0.1") -# MYSQL_HOST = os.getenv("MYSQL_HOST", "192.168.1.85") MYSQL_PORT = int(os.getenv("MYSQL_PORT", "3306")) MYSQL_USER = os.getenv("MYSQL_USER", "root") MYSQL_PWD = os.getenv("MYSQL_PWD", "123456") MYSQL_DB = os.getenv("MYSQL_DB", "mysql") +############### Data Path ############### +UPLOAD_PATH = os.getenv("UPLOAD_PATH", "tmp/qa-data") ############### Number of log files ############### LOGS_NUM = int(os.getenv("logs_num", "0")) - -############## Model path ################# -MODEL_PATH = 'models/paraphrase-mpnet-base-v2' diff --git a/solutions/nlp/question_answering_system/server/src/encode.py b/solutions/nlp/question_answering_system/server/src/encode.py index dc5e6e920..8c82ab8a1 100644 --- a/solutions/nlp/question_answering_system/server/src/encode.py +++ b/solutions/nlp/question_answering_system/server/src/encode.py @@ -1,31 +1,28 @@ -from sentence_transformers import SentenceTransformer -from sklearn.preprocessing import normalize -from config import MODEL_PATH -import gdown -import zipfile -import os +from towhee import ops, pipe class SentenceModel: """ - Say something about the ExampleCalass... - - Args: - args_0 (`type`): - ... + SentenceModel """ def __init__(self): - if not os.path.exists(MODEL_PATH): - os.makedirs(MODEL_PATH) - if not os.path.exists("./paraphrase-mpnet-base-v2.zip"): - url = 'https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/paraphrase-mpnet-base-v2.zip' - gdown.download(url) - with zipfile.ZipFile('paraphrase-mpnet-base-v2.zip', 'r') as zip_ref: - zip_ref.extractall(MODEL_PATH) - self.model = SentenceTransformer(MODEL_PATH) + self.sentence_embedding_pipe = ( + pipe.input('sentence') + .map('sentence', 'embedding', ops.sentence_embedding.sbert(model_name='all-MiniLM-L12-v2')) + .map('embedding', 'embedding', ops.towhee.np_normalize()) + .output('embedding') + ) + + def sentence_encode(self, data_list): + res_list = [] + for data in data_list: + res = self.sentence_embedding_pipe(data) + res_list.append(res.get()[0]) + return res_list + - def sentence_encode(self, data): - embedding = self.model.encode(data) - sentence_embeddings = normalize(embedding) - return sentence_embeddings.tolist() +if __name__ == '__main__': + MODEL = SentenceModel() + # Warm up the model to build image + MODEL.sentence_encode(['hello world']) diff --git a/solutions/nlp/question_answering_system/server/src/main.py b/solutions/nlp/question_answering_system/server/src/main.py index ea96bd58a..16552ef44 100644 --- a/solutions/nlp/question_answering_system/server/src/main.py +++ b/solutions/nlp/question_answering_system/server/src/main.py @@ -1,16 +1,17 @@ -import uvicorn import os +import uvicorn from fastapi import FastAPI, File, UploadFile from starlette.middleware.cors import CORSMiddleware + +from config import UPLOAD_PATH +from logs import LOGGER from milvus_helpers import MilvusHelper from mysql_helpers import MySQLHelper +from encode import SentenceModel from operations.load import do_load from operations.search import do_search, do_get_answer from operations.count import do_count from operations.drop import do_drop -from logs import LOGGER -from encode import SentenceModel - app = FastAPI() origins = ["*"] @@ -28,21 +29,18 @@ MILVUS_CLI = MilvusHelper() MYSQL_CLI = MySQLHelper() +# Mkdir '/tmp/qa-data' +if not os.path.exists(UPLOAD_PATH): + os.makedirs(UPLOAD_PATH) + @app.post('/qa/load_data') async def do_load_api(file: UploadFile = File(...), table_name: str = None): try: text = await file.read() - fname = file.filename - dirs = "QA_data" - if not os.path.exists(dirs): - os.makedirs(dirs) - fname_path = os.path.join(os.getcwd(), os.path.join(dirs, fname)) + fname_path = os.path.join(UPLOAD_PATH, file.filename) with open(fname_path, 'wb') as f: f.write(text) - except Exception: - return {'status': False, 'msg': 'Failed to load data.'} - try: total_num = do_load(table_name, fname_path, MODEL, MILVUS_CLI, MYSQL_CLI) LOGGER.info(f"Successfully loaded data, total count: {total_num}") return {'status': True, 'msg': f"Successfully loaded data: {total_num}"}, 200 @@ -55,8 +53,6 @@ async def do_load_api(file: UploadFile = File(...), table_name: str = None): async def do_get_question_api(question: str, table_name: str = None): try: questions, _= do_search(table_name, question, MODEL, MILVUS_CLI, MYSQL_CLI) - #res = dict(zip(questions, distances)) - # res = sorted(res.items(), key=lambda item: item[1]) LOGGER.info("Successfully searched similar images!") return {'status': True, 'msg': questions}, 200 except Exception as e: @@ -76,7 +72,6 @@ async def do_get_answer_api(question: str, table_name: str = None): @app.post('/qa/count') async def count_images(table_name: str = None): - # Returns the total number of questions in the system try: num = do_count(table_name, MILVUS_CLI) LOGGER.info("Successfully count the number of questions!") @@ -88,7 +83,6 @@ async def count_images(table_name: str = None): @app.post('/qa/drop') async def drop_tables(table_name: str = None): - # Delete the collection of Milvus and MySQL try: status = do_drop(table_name, MILVUS_CLI, MYSQL_CLI) LOGGER.info("Successfully drop tables in Milvus and MySQL!") diff --git a/solutions/nlp/question_answering_system/server/src/milvus_helpers.py b/solutions/nlp/question_answering_system/server/src/milvus_helpers.py index 02696a3fa..15249d4ef 100644 --- a/solutions/nlp/question_answering_system/server/src/milvus_helpers.py +++ b/solutions/nlp/question_answering_system/server/src/milvus_helpers.py @@ -1,81 +1,74 @@ import sys -from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection, utility - from config import MILVUS_HOST, MILVUS_PORT, VECTOR_DIMENSION, METRIC_TYPE +from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection, utility from logs import LOGGER + class MilvusHelper: """ - class + Milvus Helper """ def __init__(self): try: self.collection = None connections.connect(host=MILVUS_HOST, port=MILVUS_PORT) - LOGGER.debug(f"Successfully connect to Milvus with IP:{MILVUS_HOST,} and PORT:{MILVUS_PORT}") + LOGGER.debug(f"Successfully connect to Milvus with HOST: {MILVUS_HOST} and PORT: {MILVUS_PORT}") except Exception as e: LOGGER.error(f"Failed to connect Milvus: {e}") sys.exit(1) def set_collection(self, collection_name): try: - if self.has_collection(collection_name): - self.collection = Collection(name=collection_name) - else: - raise Exception(f"There has no collection named:{collection_name}") + self.collection = Collection(name=collection_name) except Exception as e: - LOGGER.error(f"Error: {e}") + LOGGER.error(f"Failed to set collection in Milvus: {e}") sys.exit(1) def has_collection(self, collection_name): # Return if Milvus has the collection try: - status = utility.has_collection(collection_name) - print(",,,,,,,,,,,,",status) - return status + return utility.has_collection(collection_name) except Exception as e: - LOGGER.error(f"Failed to check collection: {e}") + LOGGER.error(f"Failed to get collection info to Milvus: {e}") sys.exit(1) def create_collection(self, collection_name): # Create milvus collection if not exists try: - if not self.has_collection(collection_name): - field1 = FieldSchema(name="id", dtype=DataType.INT64, descrition="int64", is_primary=True,auto_id=True) - field2 = FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, descrition="float vector", dim=VECTOR_DIMENSION, is_primary=False) - schema = CollectionSchema(fields=[ field1,field2], description="collection description") - self.collection = Collection(name=collection_name, schema=schema) - LOGGER.debug(f"Create Milvus collection: {self.collection}") + field1 = FieldSchema(name="id", dtype=DataType.INT64, descrition="int64", is_primary=True, auto_id=True) + field2 = FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, descrition="float vector", + dim=VECTOR_DIMENSION, is_primary=False) + schema = CollectionSchema(fields=[field1, field2], description="collection description") + self.collection = Collection(name=collection_name, schema=schema) + LOGGER.debug(f"Create Milvus collection: {collection_name}") return "OK" except Exception as e: - LOGGER.error(f"Failed to create collection: {e}") + LOGGER.error(f"Failed create collection in Milvus: {e}") sys.exit(1) def insert(self, collection_name, vectors): # Batch insert vectors to milvus collection try: - self.create_collection(collection_name) - self.create_index(collection_name) - data = [vectors] self.set_collection(collection_name) + data = [vectors] mr = self.collection.insert(data) - ids = mr.primary_keys - self.collection.load() - LOGGER.debug(f"Insert vectors to Milvus in collection: {collection_name} with {len(vectors)} rows") + ids = mr.primary_keys + LOGGER.debug( + f"Insert vectors to Milvus in collection: {collection_name} with {len(vectors)} rows") return ids except Exception as e: - LOGGER.error(f"Failed to insert data into Milvus: {e}") + LOGGER.error(f"Failed to insert data to Milvus: {e}") sys.exit(1) def create_index(self, collection_name): # Create IVF_FLAT index on milvus collection try: self.set_collection(collection_name) - default_index= {"index_type": "IVF_SQ8", "metric_type": METRIC_TYPE, "params": {"nlist": 16384}} - status= self.collection.create_index(field_name="embedding", index_params=default_index) + default_index = {"metric_type": METRIC_TYPE, "index_type": "IVF_FLAT", "params": {"nlist": 2048}} + status = self.collection.create_index(field_name="embedding", index_params=default_index) if not status.code: LOGGER.debug( - f"Successfully create index in collection:{collection_name} with param:{default_index}") + f"Successfully create index in collection:{collection_name} with param:{default_index}") return status else: raise Exception(status.message) @@ -84,7 +77,7 @@ def create_index(self, collection_name): sys.exit(1) def delete_collection(self, collection_name): - # Delete Milvus collection + # Delete Milvus collection try: self.set_collection(collection_name) self.collection.drop() @@ -98,23 +91,23 @@ def search_vectors(self, collection_name, vectors, top_k): # Search vector in milvus collection try: self.set_collection(collection_name) - search_params = {"metric_type": METRIC_TYPE, "params": {"nprobe": 16}} - res=self.collection.search(vectors, anns_field="embedding", param=search_params, limit=top_k) - print(res[0]) + self.collection.load() + search_params = {"metric_type": METRIC_TYPE, "params": {"nprobe": 16}} + res = self.collection.search(vectors, anns_field="embedding", param=search_params, limit=top_k) LOGGER.debug(f"Successfully search in collection: {res}") return res except Exception as e: - LOGGER.error(f"Failed to search in Milvus: {e}") + LOGGER.error(f"Failed to search vectors in Milvus: {e}") sys.exit(1) def count(self, collection_name): - # Get the number of milvus collection + # Get the number of milvus collection try: self.set_collection(collection_name) - num =self.collection.num_entities + self.collection.flush() + num = self.collection.num_entities LOGGER.debug(f"Successfully get the num:{num} of the collection:{collection_name}") return num except Exception as e: LOGGER.error(f"Failed to count vectors in Milvus: {e}") - sys.exit(1) - + sys.exit(1) \ No newline at end of file diff --git a/solutions/nlp/question_answering_system/server/src/operations/__init__.py b/solutions/nlp/question_answering_system/server/src/operations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/nlp/question_answering_system/server/src/operations/count.py b/solutions/nlp/question_answering_system/server/src/operations/count.py index 878ffe4c2..b1819387d 100644 --- a/solutions/nlp/question_answering_system/server/src/operations/count.py +++ b/solutions/nlp/question_answering_system/server/src/operations/count.py @@ -1,11 +1,10 @@ import sys - -sys.path.append("..") from config import DEFAULT_TABLE from logs import LOGGER +from milvus_helpers import MilvusHelper -def do_count(table_name, milvus_cli): +def do_count(table_name: str, milvus_cli: MilvusHelper): if not table_name: table_name = DEFAULT_TABLE try: diff --git a/solutions/nlp/question_answering_system/server/src/operations/drop.py b/solutions/nlp/question_answering_system/server/src/operations/drop.py index 7862add61..cfeae7a55 100644 --- a/solutions/nlp/question_answering_system/server/src/operations/drop.py +++ b/solutions/nlp/question_answering_system/server/src/operations/drop.py @@ -1,18 +1,17 @@ import sys - -sys.path.append("..") from config import DEFAULT_TABLE from logs import LOGGER +from milvus_helpers import MilvusHelper +from mysql_helpers import MySQLHelper -def do_drop(table_name, milvus_cli, mysql_cli): +def do_drop(table_name: str, milvus_cli: MilvusHelper, mysql_cli: MySQLHelper): if not table_name: table_name = DEFAULT_TABLE try: if not milvus_cli.has_collection(table_name): msg = f"Milvus doesn't have a collection named {table_name}" return msg - #return {'status': True, 'msg': msg} status = milvus_cli.delete_collection(table_name) mysql_cli.delete_table(table_name) return status diff --git a/solutions/nlp/question_answering_system/server/src/operations/load.py b/solutions/nlp/question_answering_system/server/src/operations/load.py index d2268259f..6d80781eb 100644 --- a/solutions/nlp/question_answering_system/server/src/operations/load.py +++ b/solutions/nlp/question_answering_system/server/src/operations/load.py @@ -1,9 +1,10 @@ import sys import pandas as pd - -sys.path.append("..") from config import DEFAULT_TABLE from logs import LOGGER +from milvus_helpers import MilvusHelper +from mysql_helpers import MySQLHelper +from encode import SentenceModel # Get the vector of question @@ -13,8 +14,6 @@ def extract_features(file_dir, model): question_data = data['question'].tolist() answer_data = data['answer'].tolist() sentence_embeddings = model.sentence_encode(question_data) - # sentence_embeddings = model.encode(question_data) - # sentence_embeddings = normalize(sentence_embeddings).tolist() return question_data, answer_data, sentence_embeddings except Exception as e: LOGGER.error(f" Error with extracting feature from question {e}") @@ -23,20 +22,19 @@ def extract_features(file_dir, model): # Combine the id of the vector and the question data into a list def format_data(ids, question_data, answer_data): - data = [] - for i in range(len(ids)): - value = (str(ids[i]), question_data[i], answer_data[i]) - data.append(value) + data = [(str(i), q, a) for i, q, a in zip(ids, question_data, answer_data)] return data # Import vectors to Milvus and data to Mysql respectively -def do_load(table_name, file_dir, model, milvus_client, mysql_cli): +def do_load(table_name: str, file_dir: str, model: SentenceModel, milvus_client: MilvusHelper, mysql_cli: MySQLHelper): if not table_name: table_name = DEFAULT_TABLE + if not milvus_client.has_collection(table_name): + milvus_client.create_collection(table_name) + milvus_client.create_index(table_name) question_data, answer_data, sentence_embeddings = extract_features(file_dir, model) ids = milvus_client.insert(table_name, sentence_embeddings) - # milvus_client.create_index(table_name) mysql_cli.create_mysql_table(table_name) mysql_cli.load_data_to_mysql(table_name, format_data(ids, question_data, answer_data)) return len(ids) diff --git a/solutions/nlp/question_answering_system/server/src/operations/search.py b/solutions/nlp/question_answering_system/server/src/operations/search.py index 36a4655d2..91500d326 100644 --- a/solutions/nlp/question_answering_system/server/src/operations/search.py +++ b/solutions/nlp/question_answering_system/server/src/operations/search.py @@ -1,18 +1,18 @@ import sys - -sys.path.append("..") from config import TOP_K, DEFAULT_TABLE from logs import LOGGER +from milvus_helpers import MilvusHelper +from mysql_helpers import MySQLHelper +from encode import SentenceModel -def do_search(table_name, question, model, milvus_client, mysql_cli): +def do_search(table_name: str, question: str, model: SentenceModel, milvus_client: MilvusHelper, mysql_cli: MySQLHelper): try: if not table_name: table_name = DEFAULT_TABLE feat = model.sentence_encode([question]) results = milvus_client.search_vectors(table_name, feat, TOP_K) vids = [str(x.id) for x in results[0]] - # print('--------------------', vids, '-----------------') questions = mysql_cli.search_by_milvus_ids(vids, table_name) distances = [x.distance for x in results[0]] return questions, distances