This psalm of lament may come from the remnant (the small group that survived) of the northern kingdom after it fell in 722 BC. The people call on God as their Shepherd and as the God of Hosts (a title that describes God as the ruler over the armies of heaven). They hope that he will return to them and restore them.
They remember the Exodus and their special relationship with the Lord. The psalm ends with a promise of renewed commitment to him (Psalm 80:18).